Sign in to follow this  
Followers 0
zackrspv

Time Conversion Help

5 posts in this topic

So,

Our new jabber server has the ability to send some data to us, but unfortunately, the requests, responses, and data is all encoded with GMT time. So, it makes it hard for me to figure out just what exactly is going on, considering that, for my application, I have to be able to send requests from the LOCAL time, encode it in GMT, send to server, receive response, DECODE to local time from GMT, and post to screen.

The problem here, is that not everyone uses the same time zone, and finding the time zone in the registry is just too slow, and too unreliable if the person doesn't auto handle daylight savings time. So, i'm stumped.

How can i convert the current time on the computer, to GMT, and then from GMT to the local time on the computer, taking into account that i have users across almost all time zones in the US?

I did a search, went through literally dozens of posts, and most pointed to the Auto3Lib UDF, but that's been removed, as have many of the _TIME* functions, so not sure where to go from here.


-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Please check the Date UDF which is part of AutoIt.

You will find what you need there.

Local to GMT/UTC: _Date_Time_TzSpecificLocalTimeToSystemTime

GMT/UTC to Local: _Date_Time_SystemTimeToTzSpecificLocalTime

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Please check the Date UDF which is part of AutoIt.

You will find what you need there.

Local to GMT/UTC: _Date_Time_TzSpecificLocalTimeToSystemTime

GMT/UTC to Local: _Date_Time_SystemTimeToTzSpecificLocalTime

I see how to use the functions, but i'm not that much of an expert on structs using Au3.

$tSystem = _Date_Time_GetSystemTime()
    $tLocal  = _Date_Time_SystemTimeToTzSpecificLocalTime(DllStructGetPtr($tSystem))
    ConsoleWrite("System time to local time .: " & _Date_Time_SystemTimeToDateTimeStr($tLocal )&@CRLF)

    $tLocal  = _Date_Time_GetLocalTime()
    $tSystem = _Date_Time_TzSpecificLocalTimeToSystemTime(DllStructGetPtr($tLocal))

Let's assume that i already have a DTG in GMT from the server, how do i plug that into the 2nd structure to convert it from System to Local time?

GMT_stamp="20110302T13:28:13"

Would be the example time stamp from the server. Which i need to convert from GMT over to Local time to display in the application. Now, I assume that i'm going to have to do some manipulations to get that to work, such as pull the date, month, year out of that, and then pull the 13:28:13 out of it as well. Which i can do via regex just fine. But how do i create the struct?


-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites

Split your string and feed it to _Date_Time_EncodeSystemTime. This functionc reates the DLL struct needed for the other functions.

Just a short answer because I'm in a hurry to leave.

See you tomorrow.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This works fine for me:

#include <date.au3>
$GMT_stamp="20110302T13:28:13"
$sYear = StringLeft($GMT_stamp, 4)
$sMonth = StringMid($GMT_stamp, 5,2)
$sDay = StringMid($GMT_stamp, 7,2)
$sHour = StringMid($GMT_stamp, 10,2)
$sMinute = StringMid($GMT_stamp, 13,2)
$sSecond = StringMid($GMT_stamp,16,2)
; Encode the string into a $tagSYSTEMTIME structure
$sEncodedGMT = _Date_Time_EncodeSystemTime($sMonth, $sDay, $sYear, $sHour, $sMinute, $sSecond)
; Convert GMT to local time
$sLocalTime = _Date_Time_SystemTimeToTzSpecificLocalTime(DllStructGetPtr($sEncodedGMT))
; Convert the $tagSYSTEMTIME structure to  a string
$sLocalTime = _Date_Time_SystemTimeToDateTimeStr($sLocalTime, 1)
ConsoleWrite($sLocalTime & @CRLF)
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0