Getting Current UTC
#15
Best of both worlds, UnixTimeStamp with almost the range of a Filetime 
(1 Jan 1601 to 31 Dec 30827) Smile

'
Code:
'Unix TimeStamp with one second resolution and almost the range of a filetime (1 Jan 1601 to 31 Dec 30827)
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN () AS LONG
  LOCAL lDebug AS LONG: TXT.WINDOW EXE.FULL$, 10,10,45,85 TO lDebug

  TXT.PRINT "Now: " & STR$(UnixtimeNowQ())
  TXT.PRINT  STR$(unixtimeQ(1601,1,1,23,59,59))
  TXT.PRINT STR$(unixtimeQ(1970,1,1,0,0,0))
  TXT.PRINT  STR$(unixtimeQ(30827,12,31,23,59,59))

  TXT.COLOR = %RGB_BLUE:TXT.PRINT:TXT.PRINT "  ....Press any key to exit": TXT.WAITKEY$: TXT.END
END FUNCTION

FUNCTION UnixTimeNowQ() AS QUAD
    LOCAL tmpTime AS IPOWERTIME
    tmpTime = CLASS "PowerTime"
    tmptime.nowUTC
    FUNCTION = tmpTime.filetime/10000000 - 11644473600
END FUNCTION

FUNCTION UnixTimeQ(y AS LONG,m AS LONG,d AS LONG, h AS LONG,mm AS LONG,s AS LONG) AS QUAD
    'Input local time, output UTC based on current UTC offset
    LOCAL tmpTime AS IPOWERTIME
    tmpTime = CLASS "PowerTime"
    tmptime.newdate(y,m,d)
    tmptime.newtime(h,mm,s)

    'debug code - comment out next line for normal function use
    TXT.PRINT tmpTime.datestring & " " & tmptime.timestringfull,

    tmptime.toUTC
    FUNCTION = tmpTime.filetime/10000000 - 11644473600
END FUNCTION
'
--
New PowerBASIC User Community Forum:
https://pbusers.org/forum
Reply


Messages In This Thread
Getting Current UTC - by Owen_English - 30.05.2025, 07:22 AM
RE: Getting Current UTC - by Kurt Kuzba - 30.05.2025, 12:32 PM
RE: Getting Current UTC - by Owen_English - 30.05.2025, 12:45 PM
RE: Getting Current UTC - by Stuart McLachlan - 31.08.2025, 04:06 AM
RE: Getting Current UTC - by Albert Richheimer - 30.05.2025, 12:54 PM
RE: Getting Current UTC - by Owen_English - 30.05.2025, 12:58 PM
RE: Getting Current UTC - by Dale Yarker - 30.05.2025, 01:09 PM
RE: Getting Current UTC - by George Bleck - 30.05.2025, 11:29 PM
RE: Getting Current UTC - by Eric Pearson - 31.08.2025, 09:19 AM
RE: Getting Current UTC - by Stuart McLachlan - 31.08.2025, 10:04 AM
RE: Getting Current UTC - by Stuart McLachlan - 01.09.2025, 07:06 AM
RE: Getting Current UTC - by Dale Yarker - 01.09.2025, 09:06 AM
RE: Getting Current UTC - by Dale Yarker - 01.09.2025, 11:02 AM
RE: Getting Current UTC - by Stuart McLachlan - 01.09.2025, 11:37 AM
RE: Getting Current UTC - by Stuart McLachlan - 03.09.2025, 07:05 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)