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
'
Reply


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

Forum Jump:


Users browsing this thread: 1 Guest(s)