GMT time...

BlitzMax Forums/BlitzMax Beginners Area/GMT time...

I think this is the strangest question ever made on this forum....How I can check (via Bmax) the 'local time', I mean the offset by GMT?
For example in Italy the GMT is +1...
I have a little problem when I try to convert the timestamp to a 'human' time...
Thanks in advance

Ask via API what timezone the user choose.

Or ask the user yourself what timezone they're in.

Ok. thanks

There are various API calls available on all the platforms for finding out this kind of information.

Google is your friend ;-)

Hi, after digging in Internet for 2 days...

'Time, day of the week, Time_Zone_Information (bad)

Import "-lkernel32"

Type TIME_ZONE_INFORMATION 'I hope it's works!!!!
	Field bias:Int
	Field standardname:String
	Field date:tsystemtime
	Field daylightname:String
	Field daylightdate:tSystemTime
	Field daylightbias:Long
End Type

Type TSYSTEMTIME 
Field wYear@@
Field wMonth@@
Field wDayOfWeek@@
Field wDay@@
Field wHour@@
Field wMinute@@
Field wSecond@@
Field wMilliseconds@@
End Type

' Must have "Win32" since windows API
Global GetLocalTime(timeBuffer:Byte Ptr) "Win32"
Global GetTimeZoneInformation:Short(timebuffer:Byte Ptr) "Win32"

kernel32 = LoadLibraryA("kernel32.dll")

If Kernel32
	getlocaltime = GetProcAddress(kernel32 , "GetLocalTime")
	GetTimeZoneInformation=GetProcAddress(kernel32,"GetTimeZoneInformation")
Else
	Notify("No lib")
EndIf

Local gmt:time_zone_information = New time_zone_information
GetTimeZoneInformation(gmt)
Print "GMT: " + Float(gmt.bias)/ -60 'don't ask me why negative...

Local time:tSystemTime = New tSystemTime
GetLocalTime(time)
Print "Year       : " + time.wYear
Print "Month       : " + time.wMonth
Print "Day of Week : " + time.wDayOfWeek
Print "Day         : " + time.wDay
Print "H M S       : " + time.wHour + ":" + time.wMinute + ":" + time.wSecond


I can recover (from GetLocalTime) only the GMT (what I'm looking for) but the others info are not correctly interpreted...Well at last it works!!!!
My only problem is: there is another syntax for using API (extern and end extern), but I have encounterd too much error...maybe it's due to the 'size' of the parameters I passed to the functions...

When I have a little time I'm starting digging again to find info for the Mac version....

What's the @@ after the fields of TSYSTEMTIME? Is tha the quick way of declaring a short? ( It's not listed as such in the docs, but that's no guarantee. )

Yes @@ --> :short, I found this after digging for 2 days...(and after many trial&errors...) I'm not a C++ expert so many C structures refers to word, uword, char & so on...It's a pain for my little brain

Handy code.

Yes @@ --> :short, I found this after digging for 2 days...(and after many trial&errors...) I'm not a C++ expert so many C structures refers to word, uword, char & so on...It's a pain for my little brain

You'll get used to it :)

Speaking of C, could you not do a multi-platform version with these?
(not sure if the declarations are exactly right, I can't quite get it working properly)

Type tm
	Field tm_sec:Int
	Field tm_min:Int
	Field tm_hour:Int
	Field tm_mday:Int
	Field tm_mon:Int
	Field tm_year:Int
	Field tm_wday:Int
	Field tm_yday:Int
	Field tm_isdst:Int
	Field tm_gmtoff:Long
	Field tm_zone:Byte Ptr
End Type


Type time_t
	Field hour:Byte
	Field minute:Byte
	Field second:Byte
	Field hsecond:Byte
End Type

Extern "C"
	Function localtime:tm(time:Byte Ptr) = "localtime"
	Function time:time_t(time:Byte Ptr) = "time"
End Extern


Maybe you could use this:
http://klepto2.kl.funpic.de/include.php?path=content/download.php&contentid=14&download=go

It is a ext Time Module which now also supports Microunix time
and it is easy to use.

Import pub.stdc

Extern "C"
	Function gmtime_:Byte Ptr(time:Byte Ptr) = "gmtime"
End Extern

Local calendarTime[1], buff:Byte[256]

time_(calendarTime)

strftime_(buff, buff.length, "%A %d %B %Y - %H:%M:%S (%Z)", localtime_(calendarTime))
Print String.FromCString(buff)

strftime_(buff, buff.length, "%A %d %B %Y - %H:%M:%S", gmtime_(calendarTime))
Print String.FromCString(buff) + " (GMT Standard Time)"

??

wtf!!! all this work for something there is already?!??! arghhhhhhhh.....
:(
well something new to understand, thanks anyway.