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())
1.619369013568e9
julia> "$t"
"1.619369013568e9"
Instead, the server needs "1619369013568"
.
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())
1.619369013568e9
julia> "$t"
"1.619369013568e9"
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"
"1619369013"
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.
You can just do round(Int, t)
.