Jump to content

simple DateTimeInZone($zone) function?


Recommended Posts

Anyone has simple DateTimeInZone($zone) function $zone is between -12 and +14

which calculates everything, including daylight saving time? odd zones can be coded as 9.5 etc

I just want 1 parameter without long complicated structures :mellow:

I tried _Date_Time_SystemTimeToTzSpecificLocalTime

but I get extra hour in some locations

Just spent two hours trying to write this thing and think I need help :P

Or better if you have function GetDateTimeAtLocation($LATITUDE,$LONGITUDE)

this could be a call to webservice like reliable site maybe Google or government etc

Thanks

Edited by tobject
Link to comment
Share on other sites

Starting with a forum search on "LocalTime", produced this.

#include <INet.au3>

Local $sCity = InputBox("Local Time", "Enter City/Town", "Toowoomba")
MsgBox(0, "Local Time", "City: " & $sCity & @CRLF & "Time: " & _GoogleTime($sCity))

; Modified from http://www.autoitscript.com/forum/index.php?showtopic=56366&view=findpost&p=427666
Func _GoogleTime($sCity)
    $sSource = _INetGetSource("http://www.google.com/search?hl=en&q=time+" & $sCity)
    $aSRE = StringRegExp($sSource, "(?i)\>(\d+:\d+[ap]m)\<", 3)
    If IsArray($aSRE) = 0 Then Return SetError(1, 0, 0)
    Return $aSRE[0]
EndFunc ;==>_GoogleTime
Link to comment
Share on other sites

Thanks

Here's another service I found with coordinates

http://worldtimeengine.com/dotime/59.9384619_30.2695335/

now what the regexpression for that one?

I can do a search for id="c0">

<div class="result">

<div class="time Afternoon" id="c0">

12:54 PM on Thursday, July 1, 2010 </div>

</div>

Edited by tobject
Link to comment
Share on other sites

Try this.

#include <INet.au3>

Local $sCoords = InputBox("Local Time", "Enter Latitude_Longitude", "-27.55_151.95")
MsgBox(0, "Local Time", "Lat._Long.: " & $sCoords & @CRLF & "Time: " & _worldtimeengine($sCoords))

; Modified from http://www.autoitscript.com/forum/index.php?showtopic=56366&view=findpost&p=427666
Func _worldtimeengine($sCoords)
    $sSource = _INetGetSource("http://worldtimeengine.com/dotime/" & $sCoords & "/")
    Local $sPattern = '(?s)(?i)\<div class="result"\>\s*\<div class=.*?\>\s*(.+?)\</div'
    $aSRE = StringRegExp($sSource, $sPattern, 3)
    If IsArray($aSRE) = 0 Then Return SetError(1, 0, 0)
    Return $aSRE[0]
EndFunc ;==>_worldtimeengine
Link to comment
Share on other sites

Thanks,

my point is its like a free hack and they charge for regular time API service

so they can pull the plug on free stuff any time

btw do you have a tool to generate regular expressions?

and is expressions and XPath the same language ?

I use SelectorGadget in Firefox to get XPath query

Link to comment
Share on other sites

  • 11 months later...

I know that this is an old post, but can someone help me out? I am trying to get this script to work, but I think google changed their page, and it is no longer working right.

Here is the code that I see when I pull the source of the page. Can someone help with the stringregexp part?

<td style="font-size: medium;"><b>22:27</b> Sunday (EDT) - <b>Time</b> in <b>Toronto, ON, Canada</b></td>

I want to extract the time only.

Starting with a forum search on "LocalTime", produced this.

#include <INet.au3>

Local $sCity = InputBox("Local Time", "Enter City/Town", "Toowoomba")
MsgBox(0, "Local Time", "City: " & $sCity & @CRLF & "Time: " & _GoogleTime($sCity))

; Modified from http://www.autoitscript.com/forum/index.php?showtopic=56366&view=findpost&p=427666
Func _GoogleTime($sCity)
    $sSource = _INetGetSource("http://www.google.com/search?hl=en&q=time+" & $sCity)
    $aSRE = StringRegExp($sSource, "(?i)\>(\d+:\d+[ap]m)\<", 3)
    If IsArray($aSRE) = 0 Then Return SetError(1, 0, 0)
    Return $aSRE[0]
EndFunc ;==>_GoogleTime
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...