Unix Timestamp

91 views
Skip to first unread message

Eduardo Motta

unread,
Jan 15, 2021, 10:06:50 AM1/15/21
to
I have the value below:
\/Date(1610484742000-0300)\/

This content is in the UNIX TIMESTAMP format

I need the result to be this below:
12/01/2021 17:52

Does anyone know how to make this conversion?

Enrico Maria Giordano

unread,
Jan 15, 2021, 11:09:19 AM1/15/21
to
Here it is:

FUNCTION MAIN()

SET CENTURY ON
SET DATE FORMAT "dd/mm/yyyy"

? UTOD( "1610484742000-0300" )

INKEY( 0 )

RETURN NIL


STATIC FUNCTION UTOD( cSer )

LOCAL nSec := INT( VAL( cSer ) / 1000 )
LOCAL nMin := INT( nSec / 60 )
LOCAL nHou := INT( nMin / 60 )
LOCAL nDay := INT( nHou / 24 )
LOCAL nZon := VAL( RIGHT( cSer, 5 ) ) / 100

LOCAL cDat := DTOC( STOD( "19700101" ) + nDay )
LOCAL cHou := STRZERO( nHou - nDay * 24 + nZon, 2 )
LOCAL cMin := STRZERO( nMin - nHou * 60, 2 )

RETURN cDat + " " + cHou + ":" + cMin

EMG

http://www.emagsoftware.it
http://www.emagsoftware.it/emgmusic
http://www.emagsoftware.it/spectrum
http://www.emagsoftware.it/tbosg

Eduardo Motta

unread,
Jan 15, 2021, 11:20:40 AM1/15/21
to
Enrico, perfect !

Great work

thanks
Message has been deleted

Eduardo Motta

unread,
Dec 5, 2021, 5:14:36 PM12/5/21
to
Enrico, I found a bug. The source code below has been corrected.

before correction:
UTOD("1638497277000-0300") // 03/12/2021 -1:07

after correction:
UTOD("1638497277000-0300") // 02/12/2021 23:07


New code:

STATIC FUNCTION UTOD( cSer )
LOCAL nSec := INT( VAL( cSer ) / 1000 )
LOCAL nMin := INT( nSec / 60 )
LOCAL nHou := INT( nMin / 60 )
LOCAL nDay := INT( nHou / 24 )
LOCAL nZon := VAL( RIGHT( cSer, 5 ) ) / 100

LOCAL cDat := DTOC( STOD( "19700101" ) + nDay )
Local nHours := nHou - nDay * 24 + nZon
LOCAL cMin := STRZERO( nMin - nHou * 60, 2 )

Local dDate := CtoD(cDat)

If nHours < 0
dDate--
nHours = nHours + 24
EndIf

RETURN DtoC(dDate) + " " + StrZero(nHours, 2) + ":" + cMin

Enrico Maria Giordano

unread,
Dec 5, 2021, 5:27:54 PM12/5/21
to
Il 05/12/2021 23:14, Eduardo Motta ha scritto:

> Enrico, I found a bug. The source code below has been corrected.

Thank you.
Reply all
Reply to author
Forward
0 new messages