Using unix datetime as String

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

julia> using Dates

julia> t = datetime2unix(now())

julia> "$t"

Instead, the server needs "1619369013568".

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

julia> t = round(Int, t)

julia> "$t"

EDIT: Simplified thanks to stevengj’s suggestion below.


Which raises the question why datetime2unix returns a Float64?

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.

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.

1 Like

You can just do round(Int, t).

1 Like