Unix timestamp converter?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
f1ster
Posts: 19
Joined: 12 Feb 2020, 01:52

Unix timestamp converter?

22 Oct 2020, 17:56

Have anyone epoch timestamp converter?

This converts current timestamp to Unix:

Code: Select all

GetUnixTimestamp(){
NowUTC := A_NowUTC
NowUTC -= 19700101000000, S
return NowUTC
}
I need to convert Unix timestamp to "YYYYMMDDHHMMSS" format.
User avatar
mikeyww
Posts: 27096
Joined: 09 Sep 2014, 18:38

Re: Unix timestamp converter?

23 Oct 2020, 00:54

Code: Select all

orig := A_Now, unix := GetUnixTimestamp(), local := unixToLocalTime(unix)
MsgBox, 64, Times, % "`n`nUnix   = " unix "`nOrig    = " orig "`nLocal  = " local
ExitApp

GetUnixTimestamp(){
 NowUTC := A_NowUTC
 NowUTC -= 1970, S
 Return NowUTC
}

unixToLocalTime(unix) {
 ; @mikeyww on 23 October 2020
 ; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=82405
 ; https://autohotkey.com/board/topic/2486-code-to-convert-fromto-unix-timestamp/
 out = %TEMP%\unixToLocalTime.tmp
 RunWait, %A_ComSpec% /c "%A_WinDir%\System32\w32tm.exe /tz >%out%",, Hide
 FileRead, timeOutput, %out%
 FileDelete, %out%
 NowLocal := 1970
 NowLocal += unix, s
 RegExMatch(timeOutput, "(DAYLIGHT) Bias: (-?\d+)min", dst)
 NowLocal += 60 * (dst1 = "DAYLIGHT") - dst2, Minutes
 Return NowLocal
}
teadrinker
Posts: 4347
Joined: 29 Mar 2015, 09:41
Contact:

Re: Unix timestamp converter?

23 Oct 2020, 01:37

Or like this:

Code: Select all

unixTime := 1603435790
time := 1970
time += unixTime, s
utcTime := time

diff -= A_NowUTC, h
time += diff, h
localTime := time

MsgBox, % "utc: " . utcTime . "`nlocal: " . localTime
:)
User avatar
mikeyww
Posts: 27096
Joined: 09 Sep 2014, 18:38

Re: Unix timestamp converter?

23 Oct 2020, 06:08

That looks much better!

Or: Isn't it actually better to do everything the hard way?....
teadrinker
Posts: 4347
Joined: 29 Mar 2015, 09:41
Contact:

Re: Unix timestamp converter?

23 Oct 2020, 08:15

I think it's better to find different ways and compare them. :)
just me
Posts: 9490
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Unix timestamp converter?

23 Oct 2020, 09:31

See UTC functions at the bottom of the script.
teadrinker
Posts: 4347
Joined: 29 Mar 2015, 09:41
Contact:

Re: Unix timestamp converter?

23 Oct 2020, 10:43

@just me As I understood, UTC_ToLocalTime() takes into account the conversion to winter and summer time?
just me
Posts: 9490
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Unix timestamp converter?

24 Oct 2020, 05:02

@teadrinker, yes (at least it should).
f1ster
Posts: 19
Joined: 12 Feb 2020, 01:52

Re: Unix timestamp converter?

25 Oct 2020, 22:01

Solved:

Code: Select all

UnixToUTC(unixTime){
	time:=1970
	time+=unixTime, s
	return time
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], jeves and 144 guests