Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Unix Timestamp functions


  • Please log in to reply
8 replies to this topic

#1 therks

therks

    Witty quote

  • Active Members
  • PipPipPipPipPipPip
  • 2,168 posts

Posted 21 August 2005 - 11:38 PM

* Aug 22 - Update to TimeMakeStamp function, now accepts default keyword for last param.

So, a while ago I asked Valik what the possibilty to implement some of the functions I'm used to in PHP might be. He pointed out that they were available through some Dll calls, and so I created these UDFs. Big thanks to him for the pointers and the help he provided.
The zip has the include file, examples for each function, and the text files for creating help documents for each function.



AutoIt Version: 3.1.1++
Language:       English
Description:    Dll wrapper functions for dealing with Unix timestamps.
Requirement(s): CrtDll.dll
Notes:          If CrtDll.dll is not available then functions will return false and set @error = 99.

Functions:
_TimeGetStamp - Get current time as Unix timestamp value.
Like the PHP time function.
-----
_TimeMakeStamp - Create Unix timestamp from input values.
Syntax: _TimeMakeStamp( [ second [, minute [, hour [, day [, month [, year [, isDST ]]]]]]] )
Like the PHP mktime function.
-----
_StringFormatTime - Get a string representation of a timestamp according to the format string given to the function.
Syntax: _StringFormatTime( "format" [, timestamp [, max length ]] )
Like the PHP strftime function.

I'm in the process of duplicating PHP's date function as well. Like Valik pointed out, it's mostly just a wrapper for strftime anyway.

Anyway, enjoy, hope somebody finds these useful.
Grab the .au3 from here.

-----
Edit: The broken URL was brought to my attention via email. I don't have it in a zip with examples, but the .au3 file is available at the above link.

Edit 2: Again the URL has been broken for a while, and again brought to my attention via email. The URL has been updated.


Edited by therks, 19 June 2013 - 01:32 PM.








#2 therks

therks

    Witty quote

  • Active Members
  • PipPipPipPipPipPip
  • 2,168 posts

Posted 23 August 2005 - 05:03 PM

Using these functions, I created this application.
Plain Text         
#NoTrayIcon #include <GuiConstants.au3> #include <UnixTime.au3> $s_DefMakeString = '%#S, %#M, %#H, %#d, %#m, %Y' $i_StampNow = _TimeGetStamp() $s_MakeStamp = _StringFormatTime($s_DefMakeString, $i_StampNow) $s_Value = _StringFormatTime('%#c', $i_StampNow) #region - GUI $gui_Main = GuiCreate('TimeStamp Tool', 265, 105) $bt_Get = GuiCtrlCreateButton('&Get current values for all fields', 5, 5, 255, 20) GuiCtrlCreateLabel('&Timestamp: ', 5, 30, 70, 20, $SS_CENTERIMAGE) $in_Stamp = GuiCtrlCreateInput($i_StampNow, 75, 30, 130, 20) $bt_Use = GuiCtrlCreateButton('&Use', 210, 30, 50, 20) GuiCtrlCreateLabel('Make &Stamp: ', 5, 55, 70, 20, $SS_CENTERIMAGE) $in_MakeStamp = GuiCtrlCreateInput($s_MakeStamp, 75, 55, 130, 20) $bt_Make = GuiCtrlCreateButton('&Make', 210, 55, 50, 20) $in_Value = GuiCtrlCreateInput($s_Value, 5, 80, 255, 20, $ES_READONLY) #endregion GuiSetState() While 1     $gm = GuiGetMsg()     Select         Case $gm = $bt_Use             $i_Stamp = GuiCtrlRead($in_Stamp)             $s_MakeStamp = _StringFormatTime($s_DefMakeString, $i_Stamp)             $s_Value = _StringFormatTime('%#c', $i_Stamp)                         GuiCtrlSetData($in_MakeStamp, $s_MakeStamp)             GuiCtrlSetData($in_Value, $s_Value)         Case $gm = $bt_Make             Dim $a_MakeParams[7] = [ default, default, default, default, default, default, default ]             $s_MakeString = StringStripWS(GuiCtrlRead($in_MakeStamp), 8)             $ai_MakeSplit = StringSplit($s_MakeString, ',')             For $i = 1 to $ai_MakeSplit[0]                 $a_MakeParams[$i - 1] = $ai_MakeSplit[$i]             Next                         $i_Stamp = _TimeMakeStamp($a_MakeParams[0], $a_MakeParams[1], $a_MakeParams[2], $a_MakeParams[3], $a_MakeParams[4], $a_MakeParams[5], $a_MakeParams[6])             $s_Value = _StringFormatTime('%#c', $i_Stamp)                         GuiCtrlSetData($in_Stamp, $i_Stamp)             GuiCtrlSetData($in_Value, $s_Value)         Case $gm = $bt_Get             $i_StampNow = _TimeGetStamp()             $s_MakeString = _StringFormatTime($s_DefMakeString, $i_StampNow)             $s_Value = _StringFormatTime('%#c', $i_StampNow)                         GuiCtrlSetData($in_Stamp, $i_StampNow)             GuiCtrlSetData($in_MakeStamp, $s_MakeString)             GuiCtrlSetData($in_Value, $s_Value)         Case $gm = $GUI_EVENT_CLOSE             ExitLoop     EndSelect WEnd


#3 OverloadUT

OverloadUT

    Seeker

  • Active Members
  • 46 posts

Posted 28 June 2006 - 08:07 PM

Thank you!! I was ripping my hair out trying to figure out a good way to generate a Unix timestamp, but I totally forgot to search Scripts and Scraps!

These functions work perfectly. :D

#4 Max Kipness

Max Kipness

    Seeker

  • Active Members
  • 37 posts

Posted 13 April 2008 - 02:45 AM

Hi -

Does anybody happen to have this UnixTime.zip file. I need to convert a unix time/date stamp to a string date.

The link that was posted in 2006 doesn't seem to work anymore.

Thanks,
Max

#5 Xenobiologist

Xenobiologist

    Xx Code~Mega xX

  • MVPs
  • 4,861 posts

Posted 13 April 2008 - 11:16 AM

Hi,

post in support.

String before
String after

Mega

Scripts & functions Organize Includes Let Scite organize the include files *new

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times


#6 -Ultima-

-Ultima-

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 267 posts

Posted 13 April 2008 - 10:56 PM

http://www.therks.com/autoit/udfs/
You'll find Saunder's UDFs there.
[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

#7 tom13

tom13

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 295 posts

Posted 26 April 2009 - 08:11 AM

file could not be found....

#8 kpuk

kpuk

    Seeker

  • Normal Members
  • 9 posts

Posted 18 July 2012 - 11:36 AM

could anyone reupload this UDF?

#9 therks

therks

    Witty quote

  • Active Members
  • PipPipPipPipPipPip
  • 2,168 posts

Posted 19 June 2013 - 01:37 PM

Updated first post with new URL.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users