$ZDATETIME. Unix epoch Milliseconds
I am trying get the Unix time stamp in milliseconds
set epochSecond= $ZDATETIME($ZTIMESTAMP,-2)*1000
but the result is not accurate as $ZDATETIME ignoring /truncating the fraction of the seconds and the milliseconds calculation is not accurate with fraction seconds
for example
set epochSecond= $ZDATETIME($ZTIMESTAMP,-2)
1675830682
when its converts to the milliseconds
it became 1675830682000. not the accurate fractional seconds.
My target system looking for the milliseconds time stamp to authenticate.
Could you please help with steps to return the unix timestamp in milliseconds
Thanks
Comments
Hi,
the issue is that $ZDATETIME tformat -2 presents posix time to the second. to get the full available precision you could use something like this:
set t=$ZTIMESTAMP
w t
66513,24732.646579
w $ZDATETIME(t,-2)_$piece(t,".",2)
1675804932646579
Thanks much, Timo. It does work
below exactly help me to achieve the desired output (unix time stamp in mille seconds)
set epochSecond = $extract($ZDATETIME($ZTIMESTAMP,-2)_$piece($ZTIMESTAMP,".",2),1,13)
write epochSecond
1675839924490
s epochMilisecond=##class(%PosixTime).LogicalToUnixTime(##class(%PosixTime).TimeStampToLogical($zdt($ztimestamp,3,1,3)))*1000