# Using unix datetime as String

**URL:** <https://discourse.julialang.org/t/using-unix-datetime-as-string/59994>\
**Category:** General Usage\
**Tags:** dates\
**Created:** [April 25, 2021, 2:48pm UTC](https://discourse.julialang.org/t/using-unix-datetime-as-string/59994 "2021-04-25T14:48:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [April 25, 2021, 2:48pm UTC](https://discourse.julialang.org/t/using-unix-datetime-as-string/59994/1 "2021-04-25T14:48:37Z")

</div>

I’m trying to pass a unix datetime to a server but am unsure how to avoid the scientific notation:

```julia
julia> using Dates

julia> t = datetime2unix(now())
1.619369013568e9

julia> "$t"
"1.619369013568e9"

```

Instead, the server needs `"1619369013568"`.

---

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [April 25, 2021, 2:51pm UTC](https://discourse.julialang.org/t/using-unix-datetime-as-string/59994/2 "2021-04-25T14:51:47Z")

</div>

Sometimes, writing down the question is enough to solve it. Continuing from the previous code block:

```julia
julia> t = round(Int, t)

julia> "$t"
"1619369013"

```

EDIT: Simplified thanks to stevengj’s suggestion below.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [April 25, 2021, 4:26pm UTC](https://discourse.julialang.org/t/using-unix-datetime-as-string/59994/3 "2021-04-25T16:26:54Z")

</div>

Which raises the question why `datetime2unix` returns a Float64?

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [April 25, 2021, 4:32pm UTC](https://discourse.julialang.org/t/using-unix-datetime-as-string/59994/4 "2021-04-25T16:32:51Z")

</div>

```julia
help?> datetime2unix
search: datetime2unix datetime2julian datetime2rata

  datetime2unix(dt::DateTime) -> Float64

  Take the given DateTime and return the number of seconds since the unix epoch 1970-01-01T00:00:00 as a Float64.

```

That seems pretty reasonable: time is real, so represent it with a floating-point number.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [April 25, 2021, 4:38pm UTC](https://discourse.julialang.org/t/using-unix-datetime-as-string/59994/5 "2021-04-25T16:38:32Z")

</div>

> **[Unix time](https://en.wikipedia.org/wiki/Unix_time)**
>
> Unix time\[a\] is a date and time representation widely used in computing. It measures time by the number of seconds that have elapsed since 00:00:00 UTC on 1 January 1970, the Unix epoch, without adjustments made due to leap seconds. In modern computing, values are sometimes stored with higher granularity, such as microseconds or nanoseconds.
> Unix time originated as the system time of Unix operating systems. It has come to be widely used in other computer operating systems, file systems, progra...

Header to search is “Representing the number”

I always thought it is an Integer by definition, now I learned that there is no mandatory type.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [April 25, 2021, 5:42pm UTC](https://discourse.julialang.org/t/using-unix-datetime-as-string/59994/6 "2021-04-25T17:42:07Z")

</div>

> [@rikh](#):
>
> `t = convert(Int, round(t, digits=0))`

You can just do `round(Int, t)`.
