GetTimeZoneInformation_

Just starting out? Need help? Post your questions and find answers here.
PowerSoft
User
User
Posts: 65
Joined: Sun Aug 16, 2015 2:54 pm

GetTimeZoneInformation_

Post by PowerSoft »

Found this piece of code.
But PB is not recognized the function "GetTimeZoneInformation_"

How to used it? :?

Code: Select all

Result = GetTimeZoneInformation_(@tzi.TIME_ZONE_INFORMATION)
Debug "unterschied zu UTC Zeit = "+Str(Result)
Debug "---------------------------------------"
Debug tzi\bias
Debug tzi\StandardName
Debug tzi\StandardDate
Debug tzi\StandardBias
Debug tzi\DaylightName
Debug tzi\DaylightDate
Debug tzi\DaylightBias
OS X 10.10.5 PB 5.31(x64)
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: GetTimeZoneInformation_

Post by mk-soft »

API: https://msdn.microsoft.com/de-de/librar ... s.85).aspx

Update

Code: Select all

Procedure.s GetTimeString(*Systemtime)
  Protected dTime.s = Space(64)
  Protected sTime.s = Space(64)
  Protected r1, r2, result.s
  r1 = GetDateFormat_(#LOCALE_USER_DEFAULT, #Null, *Systemtime, #Null, @dTime, 64)
  r2 = GetTimeFormat_(#LOCALE_USER_DEFAULT, #TIME_FORCE24HOURFORMAT, *Systemtime, #Null, @sTime, 64)
  If r1
    result = dTime
  EndIf
  If r1 And r2
    result + " "
  EndIf
  If r2
    result + stime
  EndIf
  ProcedureReturn result
EndProcedure


GetSystemTime_(time.systemtime)
Debug "Systemtime: " + GetTimeString(time)
GetLocalTime_(time.systemtime)
Debug "Localtime: " + GetTimeString(time)

Result = GetTimeZoneInformation_(@tzi.TIME_ZONE_INFORMATION)
Debug "Result: "+ Result
Debug "---------------------------------------"
Debug "Bias: " +  tzi\bias
Debug "Name: " + PeekS(@tzi\StandardName)
Debug "StandardDate: " + GetTimeString(tzi\StandardDate)

Debug "StandardBias: " + tzi\StandardBias
Debug "DaylightName: " + PeekS(@tzi\DaylightName)
Debug "DaylightDate: " + GetTimeString(tzi\DaylightDate)
Debug "DaylightBias: " + tzi\DaylightBias
__________________________________________________
URL tags added
27.04.2017
RSBasic
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PowerSoft
User
User
Posts: 65
Joined: Sun Aug 16, 2015 2:54 pm

Re: GetTimeZoneInformation_

Post by PowerSoft »

mk-soft wrote:API: https://msdn.microsoft.com/de-de/librar ... s.85).aspx

Update

Code: Select all

Procedure.s GetTimeString(*Systemtime)
  Protected dTime.s = Space(64)
  Protected sTime.s = Space(64)
  Protected r1, r2, result.s
  r1 = GetDateFormat_(#LOCALE_USER_DEFAULT, #Null, *Systemtime, #Null, @dTime, 64)
  r2 = GetTimeFormat_(#LOCALE_USER_DEFAULT, #TIME_FORCE24HOURFORMAT, *Systemtime, #Null, @sTime, 64)
  If r1
    result = dTime
  EndIf
  If r1 And r2
    result + " "
  EndIf
  If r2
    result + stime
  EndIf
  ProcedureReturn result
EndProcedure


GetSystemTime_(time.systemtime)
Debug "Systemtime: " + GetTimeString(time)
GetLocalTime_(time.systemtime)
Debug "Localtime: " + GetTimeString(time)

Result = GetTimeZoneInformation_(@tzi.TIME_ZONE_INFORMATION)
Debug "Result: "+ Result
Debug "---------------------------------------"
Debug "Bias: " +  tzi\bias
Debug "Name: " + PeekS(@tzi\StandardName)
Debug "StandardDate: " + GetTimeString(tzi\StandardDate)

Debug "StandardBias: " + tzi\StandardBias
Debug "DaylightName: " + PeekS(@tzi\DaylightName)
Debug "DaylightDate: " + GetTimeString(tzi\DaylightDate)
Debug "DaylightBias: " + tzi\DaylightBias
When compiling this code got an error at:
GetDateFormat_(#LOCALE_USER_DEFAULT, #Null, *Systemtime, #Null, @dTime, 64)

Line 5: GetDateFormat_() is not a function, array, list, map or macro.

How to get this running?
OS X 10.10.5 PB 5.31(x64)
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: GetTimeZoneInformation_

Post by mk-soft »

It´s all only with Window-OS

I don´t know it on MacOS
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: GetTimeZoneInformation_

Post by Shardik »

Did you already try whether my MacOS example may help you?
PowerSoft
User
User
Posts: 65
Joined: Sun Aug 16, 2015 2:54 pm

Re: GetTimeZoneInformation_

Post by PowerSoft »

Shardik wrote:Did you already try whether my MacOS example may help you?
This is perfect, just what I need for my program
OS X 10.10.5 PB 5.31(x64)
PowerSoft
User
User
Posts: 65
Joined: Sun Aug 16, 2015 2:54 pm

Re: GetTimeZoneInformation_

Post by PowerSoft »

Thanks again for this routine. It is very useful for me. :lol:
Is it posible to extract only the value 7200 from the message, this is the offset I need from UTC.



Outcomming:
Daylight saving is activated.
Time offset = 60 minutes
Time zone description: Europe/Amsterdam (CEST) offset 7200 (Daylight)
Next daylight saving transition: 2017-10-29 01:00:00
OS X 10.10.5 PB 5.31(x64)
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: GetTimeZoneInformation_

Post by Shardik »

PowerSoft wrote:Is it posible to extract only the value 7200 from the message, this is the offset I need from UTC.

Code: Select all

Define TimeZoneDescription.S
Define TimeZoneObject.I

TimeZoneObject = CocoaMessage(0, 0, "NSTimeZone systemTimeZone")
TimeZoneDescription = PeekS(CocoaMessage(0, CocoaMessage(0,
   TimeZoneObject, "description"), "UTF8String"), -1, #PB_UTF8)
MessageRequester("Offset", StringField(TimeZoneDescription, 4, " "))
PowerSoft
User
User
Posts: 65
Joined: Sun Aug 16, 2015 2:54 pm

Re: GetTimeZoneInformation_

Post by PowerSoft »

Thanks just what I needed :lol: :lol:
OS X 10.10.5 PB 5.31(x64)
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: GetTimeZoneInformation_

Post by wilbert »

Another option would be to use secondsFromGMT

Code: Select all

Offset = CocoaMessage(0, CocoaMessage(0, 0, "NSTimeZone systemTimeZone"), "secondsFromGMT")
Debug Offset
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply