Getting Current UTC
#11
Tidied up functions for UNIX TimeStamp, FileTime seconds and current UTC ISO DateTime as strings, all with optional fractional seconds (up to msecs)

'
Code:
' Current Unix Time, FileTime seconds and ISO UTC DateTime
' to a maximum of 3 decimal places!!!
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN () AS LONG
    LOCAL s AS STRING
    ? "UnixTime:" & $LF & UnixTimeNowStr & $LF & UnixTimeNowStr(1) & $LF & $LF _
      & "Filetime: " & $LF & FileTimeNowStr & $LF & FileTimeNowStr(2) & $LF & $LF _
      & "ISO DateTime: " & $LF & ISONowUTCStr & $LF & ISONowUTCStr(3) & $LF,, "UTC TimeStamps"
END FUNCTION

FUNCTION UnixTimeNowStr((OPT BYVAL decplaces AS LONG) AS STRING
    LOCAL tmpTime AS IPOWERTIME, fmt AS STRING
    fmt = "0"
    IF decplaces > 3 THEN decplaces = 3
    IF decplaces > 0 THEN fmt &= "." & STRING$(decplaces,"0")
    tmpTime = CLASS "PowerTime"
    tmptime.nowUtc
    FUNCTION = FORMAT$(tmpTime.filetime/10000000 - 11644473600,fMt)
END FUNCTION

FUNCTION FileTimeNowStr(OPT BYVAL decplaces AS LONG) AS STRING
    LOCAL tmpTime AS IPOWERTIME, fmt AS STRING
    tmpTime = CLASS "PowerTime"
    tmptime.NowUTC
    fmt = "0"
    IF decplaces > 3 THEN decplaces = 3
    IF decplaces > 0 THEN fmt &= "." & STRING$(decplaces,"0")
    FUNCTION = FORMAT$(tmpTime.Filetime /10^7,fmt)
END FUNCTION

FUNCTION ISONowUTCStr(OPT BYVAL decplaces AS LONG) AS STRING
  LOCAL tmpTime AS IPOWERTIME, s AS STRING
    tmpTime = CLASS "PowerTime"
    tmptime.NowUTC
    s = CHR$(FORMAT$(tmpTime.Year,"0000"),FORMAT$(tmpTime.Month,"00"),FORMAT$(tmpTime.Day,"00"),"T", _
              FORMAT$(tmpTime.Hour,"00"),FORMAT$(tmpTime.Minute,"00"),FORMAT$(tmpTime.Second,"00"))
    IF decplaces > 3 THEN decplaces = 3
    IF decplaces > 0 THEN s &= "." & FORMAT$(CINT(tmpTime.msecond/10^(3-decplaces)))
    FUNCTION = s & "Z"
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 - 09-03-2025, 06:05 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)