'Compiles as-is in PBWin 10 or PBCC 6.
#compile exe
#dim all
#if %pb_cc32 'Ignored by PBWin, no need to remove.
#console off 'Stops creation of unneeded console in PBCC
#endif
type SYSTEMTIME
wYear as word
wMonth as word
wDayOfWeek as word
wDay as word
wHour as word
wMinute as word
wSecond as word
wMilliseconds as word
end type
declare function SystemTimeToFileTime lib "Kernel32.dll" _
alias "SystemTimeToFileTime" (lpSystemTime as SYSTEMTIME, _
lpFileTime as quad) as long
declare function FileTimeToSystemTime lib "Kernel32.dll" _
alias "FileTimeToSystemTime" (lpFileTime as quad, _
lpSystemTime as SYSTEMTIME) as long
function pbmain () as long
local ST as systemtime
local FT as quad
local hTxt as dword
local x as word
txt.window("About FILETIME and SYSTEMTIME", 200, 150, 24, 65) to hTxt
FT = &h8000000000000000
txt.print " A FileTime of &h8000000000000000 returns:"
txt.print FileTimeToSystemTime (FT, ST); " 'zero if error"
txt.print
txt.print "&h8000000000000000 - 1 = &h7FFFFFFFFFFFFFFF";
FT = &h7FFFFFFFFFFFFFFF
txt.print " 'which returns:"
txt.print FileTimeToSystemTime (FT, ST); " 'non-zero if success"
txt.print "Making it the maximum FileTime. Or,"
txt.print dec$(ST.wYear, 4); "-"; dec$(ST.wMonth, 2); "-";
txt.print dec$(ST.wDay, 2); "T"; dec$(ST.wHour, 2); ":";
txt.print dec$(ST.wMinute, 2); ":"; dec$(ST.wSecond, 2); ".";
txt.print dec$(FT mod 10000000 , 7); "Z";
txt.print " 'ISO 8601 format from SystemTime."
txt.print
txt.print " "; string$$(63, "=")
txt.print
txt.print "SystemTimeToFileTime returns as error with that SystemTime."
txt.print "The latest SystemTime that does not error is:"
txt.print "ST.wYear = 30827" tab(20)
txt.print "ST.wMonth = 12" tab(40)
txt.print "ST.wDay = 31"
txt.print "ST.wHour = 23" tab(20)
txt.print "ST.wMinute = 59" tab(40)
txt.print "ST.wSecond = 59"
txt.print "ST.wmilliseconds = 999"
txt.print
txt.print "So the maximum SystemTime is in ISO 8601 is:"
ST.wYear = 30827 : ST.wMonth = 12 : ST.wDay = 31
ST.wHour = 23 : ST.wMinute = 59 : ST.wSecond = 59
ST.wmilliseconds = 999
txt.print dec$(ST.wYear, 4); "-"; dec$(ST.wMonth, 2); "-";
txt.print dec$(ST.wDay, 2); "T"; dec$(ST.wHour, 2); ":";
txt.print dec$(ST.wMinute, 2); ":"; dec$(ST.wSecond, 2); ".";
txt.print dec$(FT mod 10000000 , 7); "Z"
txt.print
txt.print "Converted to FileTime:"
SystemTimeToFileTime (ST, FT)
txt.print "&h";hex$(FT, 16)
txt.print
txt.print "Any key to exit.
txt.waitkey$
end function
Done with this window?