Question Dhivakar Karimuth · Feb 7, 2023

$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

Product version: IRIS 2021.2
$ZV: IRIS for UNIX (Ubuntu Server LTS for x86-64 Containers) 2021.2 (Build 651U) Mon Jan 31 2022 18:07:01 EST

Comments

Timo Lindenschmid · Feb 8, 2023

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

0
Dhivakar Karimuth  Feb 8, 2023 to Timo Lindenschmid

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

0
Adam Škůrek · Feb 8, 2023

s epochMilisecond=##class(%PosixTime).LogicalToUnixTime(##class(%PosixTime).TimeStampToLogical($zdt($ztimestamp,3,1,3)))*1000

0