I need to create a chrono::DateTime<Local>
instance that is set to a specific date and time. For example, I need to create a DateTime<Local>
instance that is set to something like 3/17/2019 at 4:43 PM (or 3/17/2019 at 16:43).
The documentation for the DateTime
struct shows how to get the current date and time via the now
function and plenty of support for getting time durations. There appears to be some confusing traits and conversion functions, but there doesn't appear to be anything that allows me to directly create a DateTime
instance that represents a specific date and time.
Is it possible to create such an instance? If so, how?
There is a function called ymd
for the TimeZone
trait that returns a date. You can then call and_hms
on this date to set a specific time.
use chrono::TimeZone;
let dt = chrono::Local.ymd(2019, 3, 17).and_hms(16, 43, 0);