Hello,
Is there a possible way to read the computer's time zone ?
For example UTC+2, UTC+3 .etc ?
Thank you
How to Read computer's time zone ?
Re: How to Read computer's time zone ?
In Linux you can do:
In Windows, there's a Win32 api call for this:
https://learn.microsoft.com/en-us/windo ... nformation
Here's a demo of that:
Code: Select all
#include "crt/time.bi"
dim as time_t t
dim as tm lt
localtime_r(@t, @lt)
print "gmt offset is "; lt.__tm_gmtoff / 3600
print "time zone is "; *lt.__tm_zone
https://learn.microsoft.com/en-us/windo ... nformation
Here's a demo of that:
Code: Select all
#include "windows.bi"
dim as DWORD result
dim as TIME_ZONE_INFORMATION ti
result = GetTimeZoneInformation(@ti)
print "Time zone is UTC";ti.bias / -60 'utc is bias seconds + localtime
select case result
case 1
print "Standard time."
case 2
print "Daylight savings time."
end select
Re: How to Read computer's time zone ?
Thank you for your reply. I implemented both solutions you suggested to my framework https://github.com/nsiatras/kiwi/wiki/k ... e.Calendarcaseih wrote: ↑Sep 27, 2022 13:09 In Linux you can do:In Windows, there's a Win32 api call for this:Code: Select all
#include "crt/time.bi" dim as time_t t dim as tm lt localtime_r(@t, @lt) print "gmt offset is "; lt.__tm_gmtoff / 3600 print "time zone is "; *lt.__tm_zone
https://learn.microsoft.com/en-us/windo ... nformation
Here's a demo of that:Code: Select all
#include "windows.bi" dim as DWORD result dim as TIME_ZONE_INFORMATION ti result = GetTimeZoneInformation(@ti) print "Time zone is UTC";ti.bias / -60 'utc is bias seconds + localtime select case result case 1 print "Standard time." case 2 print "Daylight savings time." end select
Windows solution works and I tested it. Unfortunately I cannot test the Linux one but I believe it is correct.
Thanks again