FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour UNIX to date
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
UNIX to date
Posted: Thu May 11, 2023 10:30 AM
I must converte a number -> time_next_update_unix



I found this function but not run ok
Code (fw): Select all Collapse
FUNCTION UnixToDate(nUnix)
   LOCAL nSecs, dDate, cTime, dDateTime
       nSecs := nUnix - 28800 // correzione fuso orario
   dDate := CTOD("01/01/1970")
   cTime := stot(nSecs / 1000)
   
   dDateTime := dDate + cTime
   
   RETURN dDateTime
chat Open Ai give me this but not run
Code (fw): Select all Collapse
FUNCTION UnixToDate(nUnix)
   LOCAL nSecs, dDate, cTime, dDateTime
   
   // Converti i secondi Unix in una data Clipper e un valore di tempo
   nSecs := nUnix - 28800 // correzione fuso orario
   dDate := CTOD("01/01/1970")
   cTime := CTOT(TIME(SECONDS(nSecs) * 1000))
   
   // Combina la data e l'ora Clipper in un valore di data e ora Clipper
   dDateTime := dDate + cTime
   
   // Restituisci la data e ora convertite
   RETURN dDateTime
ho I can resolve ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: UNIX to date
Posted: Fri May 12, 2023 05:22 AM
Once we know that 1970-01-01 is the epoch date in Unix, it is very easy to write the conversion:
Code (fw): Select all Collapse
function UnixToDateTime( nUnixDate )
return HB_STOT( "19700101000000" ) + ( nUnixDate / 24.0 / 3600.0 )
This returns the harbor DateTime value.

Testing from India:
present UTC nUnixTime is 1683872102
? tUTC := UnixToDateTime( nUnixTime ) // 12-05-2023 06:15:02
? tLocal := FW_UTCTOLOCAL( tUtc ) // 12-05-2023 11:45:02

Compare your test results with
https://www.epochconverter.com/
Regards



G. N. Rao.

Hyderabad, India
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: UNIX to date
Posted: Fri May 12, 2023 07:47 AM
nageswaragunupudi wrote:Once we know that 1970-01-01 is the epoch date in Unix, it is very easy to write the conversion:
Code (fw): Select all Collapse
function UnixToDateTime( nUnixDate )
return HB_STOT( "19700101000000" ) + ( nUnixDate / 24.0 / 3600.0 )
This returns the harbor DateTime value.

Testing from India:
present UTC nUnixTime is 1683872102
? tUTC := UnixToDateTime( nUnixTime ) // 12-05-2023 06:15:02
? tLocal := FW_UTCTOLOCAL( tUtc ) // 12-05-2023 11:45:02

Compare your test results with
https://www.epochconverter.com/
thanks I resolve
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion