tiho
tiho

Reputation: 6935

Converting from DateTime to string in Julia

Is there any user-friendly and efficient function to convert from a DateTime into a string? I'm thinking of something that would look like string(mydate, mydateformat), used for instance with mydate = Dates.now() and mydateformat = Dates.DateFormat("yyyy-mm-dd H:M:S").

Upvotes: 16

Views: 12031

Answers (1)

quinnj
quinnj

Reputation: 1268

Thanks for asking this question; I realized I forgot to document the important Dates.format(dt::TimeType, df::DateFormat) function!

The usage is pretty much what you're looking for:

julia> dt = DateTime(2015,7,15,3,2)
2015-07-15T03:02:00

julia> Dates.format(dt, "yyyy-mm-dd HH:MM:SS")
"2015-07-15 03:02:00"

Upvotes: 29

Related Questions