Reputation: 609
I am using Julia 0.3.0 on Windows 8.1
These examples came from the Datetime manual at https://github.com/quinnj/Datetime.jl/wiki/Datetime-Manual
I tried this:
julia> using datetime
Warning: requiring "datetime" did not define a corresponding module.
julia> date(2013,7,1)
ERROR: date not defined
julia> today()
ERROR: today not defined
julia> dt = date(2013,7,1)
ERROR: date not defined
julia> dt = datetime(2012,6,30,18,59,50,0,CST)
ERROR: datetime not defined
julia> datetime(2013,7,1,12,0,0,0,UTC)
ERROR: datetime not defined
How do I create a datetime object? I understand that DateTime will be deprecated and that Dates will be the new datetime module. I added that package but I can't find any intructions on how to use it.
Upvotes: 4
Views: 2938
Reputation: 1511
An update using Julia 1.5.1 to solve it:
/Applications/Julia-1.5.app/Contents/Resources/julia/bin/julia
NOTE: replace the full path with the path you have julia installed at (or even better add it to the global PATH variable)
julia> import Pkg
julia> Pkg.add("Dates")
And that's it !!
Now you should be able to run julia programs with a code like:
using Dates
println(DateTime(2020))
More info about the Dates julia API can be found at https://docs.julialang.org/en/v1/stdlib/Dates/
Upvotes: 1
Reputation: 285
An update just in case somebody still read this (first result on duckduckgo): julia Datetime is deprecated since from julia 0.4-dev there's the package Dates that got merged.
So, the right way nowadays (julia 0.5, 0.6) is to use Base.Dates like in
Base.Dates.today()
or in
import Base.Dates; now()
Upvotes: 1
Reputation: 609
I found the solution. Uninstall/Reinstall Julia to get rid of Datetime package. run Pkg.add("Dates"), user manual here docs.julialang.org/en/latest/manual/dates
Upvotes: 0
Reputation: 11664
The first line should be using Datetime
, after installing the Datetime package with Pkg.add("Datetime")
.
julia> using Datetime
julia> date(2013,7,1)
2013-07-01
julia> today()
2014-09-01
julia> dt = date(2013,7,1)
2013-07-01
julia> dt = datetime(2012,6,30,18,59,50,0,CST)
2012-06-30T18:59:50 CDT
julia> datetime(2013,7,1,12,0,0,0,UTC)
2013-07-01T12:00:00 UTC
Until Julia 0.4, you should stick with this.
Upvotes: 2