LB Booster
Programming >> BASIC code examples >> Coordinated Universal Time (UTC)
http://lbb.conforums.com/index.cgi?board=code&action=display&num=1459805586

Coordinated Universal Time (UTC)
Post by Richard Russell on Apr 4th, 2016, 9:33pm

There is a thread at the Liberty BASIC Community Forum asking how to get the current UTC time. This is quite straightforward using the Windows API, but for some reason nobody seems to have posted the code to do it. Instead various complicated or non-working solutions have been offered.

For the record, here is a simple example of how to print the UTC time in LB or LBB:

Code:
    struct st, wYear as word, wMonth as word, wDayOfWeek as word, _ 
        wDay as word, wHour as word, wMinute as word, wSecond as word, _ 
        wMilliseconds as word
        
    calldll #kernel32, "GetSystemTime", st as struct, ret as long
    
    print "The current time (UTC) is "; dig2$(st.wHour.struct); ":"; _
        dig2$(st.wMinute.struct); ":"; dig2$(st.wSecond.struct)
    end
    
function dig2$(n)
    dig2$ = right$("0" + str$(n), 2)
end function 

Richard.

Re: Coordinated Universal Time (UTC)
Post by cocos on Apr 6th, 2016, 2:10pm

Hi Richard,

your program works perfect - I have already integrated it into my program.

Thank you very much!
daniel

P.S. Shall I post it on the other forum as well to have a closed loop or do you prefer not to?
Re: Coordinated Universal Time (UTC)
Post by Richard Russell on Apr 6th, 2016, 7:05pm

on Apr 6th, 2016, 2:10pm, cocos wrote:
Shall I post it on the other forum as well to have a closed loop or do you prefer not to?

It's entirely up to you. I can't post it there myself, but any code I publish is of course free for all to use.

If the code is in any way 'original' an acknowledgement would be appreciated, but in this case it's nothing more than a trivial call to an API function.

Richard.