How to elegantly convert from DateObject
to TimeObject
?
The purpose is to extract time from the DateObject and manipulate only time components afterwards.
How to elegantly convert from DateObject
to TimeObject
?
The purpose is to extract time from the DateObject and manipulate only time components afterwards.
TimeObject
can take a DateObject
so:
datetime = DateObject[]
time = TimeObject[datetime]
Since the FullForm
of a DateObject
looks like this:
DateObject[List[2015,8,27],TimeObject[List[17,58,23.456762],Rule[TimeZone,-5.]],Rule[TimeZone,-5.]]
we can use Cases
:
now = DateObject[]
Cases[now, TimeObject[__]][[1]]
Or even simpler:
now[[2]]
DateObject[{2019, 5, 21, 12, 55, 24.6968067}, "Instant", "Gregorian", 2.]
.
$\endgroup$
May 21, 2019 at 10:59