datetime to unix time converter
datetime to unix time converter
Does anyone have a function that converts Xbase++ date and time to Unix time?
The eXpress train is coming - and it has more cars.
Re: datetime to unix time converter
Hi Roger
Unix time function, see library ot4xb. dll by Pablo Botella
Best Regard
Hector Pezoa
Feliz Navidad y Prospero Año Nuevo
Unix time function, see library ot4xb. dll by Pablo Botella
Best Regard
Hector Pezoa
Feliz Navidad y Prospero Año Nuevo
- Attachments
-
- ot4xb-time-functions-and-classes (1).rar
- Time function
- (146.07 KiB) Downloaded 895 times
Re: datetime to unix time converter
Hi Roger
You can download this library from this site
http://www.xbwin.com/download/
Best Regard
Hector Pezoa
You can download this library from this site
http://www.xbwin.com/download/
Best Regard
Hector Pezoa
Re: datetime to unix time converter
After posting my message, I realized that it would be a simple algorithm, written entirely in Xbase++. Here is the code:
Code: Select all
FUNCTION DC_DateTime2UnixTime( dCurrDate, cCurrTime )
LOCAL nSeconds := 0, nYear, dDate, nDays
DEFAULT dCurrDate := Date(), ;
cCurrTime := Time()
nYear := 1970
DO WHILE nYear < Year(dCurrDate)
dDate := StoD(Str(nYear,4,0)+'0101')
IF IsLeap(dDate)
nDays := 366
ELSE
nDays := 365
ENDIF
nSeconds += (nDays * 86400)
nYear ++
ENDDO
nDays := Doy(dCurrDate-1)
nSeconds += (nDays * 86400)
nSeconds += TimeToSec(cCurrTime)
RETURN nSeconds
The eXpress train is coming - and it has more cars.
Re: datetime to unix time converter
Here is the reverse function:
Code: Select all
FUNCTION DC_UnixTime2DateTime( nSeconds )
LOCAL dDate, cTime, nYear, nDays, nSecsFromMidnight
IF Empty(nSeconds)
nSeconds := DC_DateTime2UnixTime()
ENDIF
nYear := 1970
DO WHILE nSeconds > 0
dDate := StoD(Str(nYear,4,0)+'0101')
IF IsLeap(dDate)
nDays := 366
ELSE
nDays := 365
ENDIF
nSeconds -= (nDays * 86400)
nYear ++
ENDDO
dDate := StoD(Str(nYear,4,0)+'0101')
nSeconds *= -1
nDays := nSeconds/86400
nSecsFromMidnight := (86400*(nDays - Int(nDays)))
dDate -= (Int(nDays) + 1)
cTime := SecToTime(86400-nSecsFromMidnight)
RETURN {dDate, cTime}
The eXpress train is coming - and it has more cars.