This is a cross-platform example to query the current GMT/UTC seconds since 1970-01-01 00:00:00. On Linux and MacOS it utilizes the date command, on Windows GetSystemTime_().
Greenwich
Mean
Time (GMT) is equivalent to the coordinated universal time (UTC):
Wikipedia wrote:Greenwich Mean Time (GMT) is the mean solar time at the Royal Observatory in Greenwich, London. GMT was formerly used as the international civil time standard, now superseded in that function by Coordinated Universal Time (UTC). Today GMT is considered equivalent to UTC for UK civil purposes (but this is not formalised) and for navigation is considered equivalent to UT1 (the modern form of mean solar time at 0° longitude); these two meanings can differ by up to 0.9 s. Consequently, the term GMT should not be used for precise purposes.[1]
I have tested the code example successfully on these operating systems:
- Linux Mint 18.1 x64 with Cinnamon and PB 5.60 x64
- MacOS 10.6.8 'Snow Leopard' with PB 5.44 x86
- Windows 7 SP1 x64 with PB 5.44 x86
Code: Select all
EnableExplicit
Define Seconds.I
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Define SystemTime.SYSTEMTIME
GetSystemTime_(@SystemTime)
Seconds = Date(SystemTime\wYear, SystemTime\wMonth, SystemTime\wDay,
SystemTime\wHour, SystemTime\wMinute, SystemTime\wSecond)
CompilerElse
Define ProgramID.I
ProgramID = RunProgram("date", "+%s", "", #PB_Program_Open | #PB_Program_Read)
If ProgramID
While ProgramRunning(ProgramID)
Seconds = Val(ReadProgramString(ProgramID) + #CR$)
Wend
CloseProgram(ProgramID)
EndIf
CompilerEndIf
MessageRequester("Seconds since 1970-01-01 00:00:00",
Str(Seconds) + " (GMT = UTC+0)" + #CR$ +
FormatDate("%yyyy-%mm-%dd %hh:%ii:%ss", Seconds))