fgilain Posted February 22, 2013 Share Posted February 22, 2013 Hello, I need to create a script using autoit on a windows computer to execute it on a remote linux server using putty (or plink) and this script needs to generate a string corresponding to the actuel date/time in the linux format (equivalent to the linux command : `/bin/date +%s`). My problem is that it seems to generate it with 1 hour more than it should be.. maybe did i missed something ? here is the code i used : $UnixDateSince1970 = _DateDiff( 's',"1970/01/01 00:00:00",_NowCalc()) Any idea of what i coul have missed ? Nb : actually, it's 2013/02/22 01:20PM in France, and the result string is : 1361539258 thanks Florent Link to comment Share on other sites More sharing options...
fgilain Posted February 22, 2013 Author Share Posted February 22, 2013 (edited) on the linux server, result is : [root@remote_linux_server]# date ven fév 22 13:22:20 CET 2013 [root@remote_linux_server]# date ven fév 22 13:22:20 CET 2013 [root@remote_linux_server]# date ven fév 22 13:22:20 CET 2013 [root@remote_linux_server]# /bin/date +%s 1361535757 seems to have 1 hour of difference too in the result ???? should i change something about the "CET" timezone somewhere on the linux ? Edited February 22, 2013 by fgilain Link to comment Share on other sites More sharing options...
water Posted February 22, 2013 Share Posted February 22, 2013 What do you get if you run "date" on the linux machine? Is it GMT time? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
jchd Posted February 22, 2013 Share Posted February 22, 2013 1 hour might be difference from UTC to local time or daylight savings. Sorting out which is which is up to you since we have no idea of both machines' settings. fgilain 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
water Posted February 22, 2013 Share Posted February 22, 2013 Seems you can specify the timezone in the datestr:"Sets the time and date to the value specfied in the datestr. The datestr may contain the month names, timezones, 'am', 'pm', etc. See examples for an example of how the date and time can be set." My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted February 22, 2013 Share Posted February 22, 2013 (edited) Here is a complete list of format control characters supported by date command.Add the timezone and see if the result changes. Edited February 22, 2013 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
fgilain Posted February 22, 2013 Author Share Posted February 22, 2013 (edited) [root@remote_linux_server]# date ven fév 22 18:14:18 CET 2013 [root@remote_linux_server]# date -u ven fév 22 17:20:55 UTC 2013 Edited February 22, 2013 by fgilain Link to comment Share on other sites More sharing options...
fgilain Posted February 22, 2013 Author Share Posted February 22, 2013 (edited) Solution would be to get the "now date" from autoit in UTC format, no ? Because actually it seems to return the GMT+1 datetime.... And what will happen at next change of hour here in france ? Edited February 22, 2013 by fgilain Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 22, 2013 Moderators Share Posted February 22, 2013 fgilain,Most users would want the local time - so that is what Autoit gives you. But you can use _Date_Time_GetTimeZoneInformation and convert to UTC yourself - look at the Help file to see how. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
fgilain Posted February 22, 2013 Author Share Posted February 22, 2013 (edited) Sorry, i'm not a "professional developer"...i'm quite lost in all theses expert solutions... As i need to generate from my windows computer a string representing the actual time (since 1970) that would be the same as if i had calculated it on my linux box (even if there were daylight saving changes), what would be the best way then ? NB :today, i just did a "- 3600" to my result to remove 1 hour in the result of my windows computer (but i suppose it won't work anymore after the next daylight change here in france ?) Edited February 22, 2013 by fgilain Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 22, 2013 Moderators Share Posted February 22, 2013 fgilain, This should do the trick: #include <Date.au3> ; Get local time $sLocal_Time = _NowTime() ConsoleWrite($sLocal_Time & @CRLF) ; Get time zone info - look in Help file to see what is in the different elements $aTime_Info = _Date_Time_GetTimeZoneInformation() ; Convert local to UTC - you need to add the date to get the correct format $sUTC_DTG = _DateAdd("n", $aTime_Info[1], _NowCalcDate() & " " & $sLocal_Time) ; Split the returned date and time $aUTC = StringSplit($sUTC_DTG, " ") ; And we have UTC time $sUTC_Time = $aUTC[2] ConsoleWrite($sUTC_Time & @CRLF) Does it? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
fgilain Posted February 25, 2013 Author Share Posted February 25, 2013 Seems to calculate correcly the time (1 hour less in UTC time) ..but what i really need is the "epoch datetime"... NB : will htis work too after next daylight change ? FG Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 25, 2013 Moderators Share Posted February 25, 2013 fgilain,So write your own function to obtain epoch time - DateDiff looks like a good place to start. I have no idea if _Date_Time_GetTimeZoneInformation takes account of the twice yearly time changes - but if you look at the Help file page for the function you can see that there is a field for daylight saving, so I imagine it probably does. You will just have to wait and see. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
kylomas Posted February 25, 2013 Share Posted February 25, 2013 fgilain, You could set the date/time on some PC to whatever date you want to test and watch it rollover... kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now