Input Timestamp with UTC Offset Using AutoHotkey

Nov. 02, 2025 in Buffalo, United States • Updated Nov. 02, 2025

Due to that when I writing a blog (hosted on Jekyll website), I need to input a date information in Front Matter block, to quickly input current time (i.e., timestamp), before I defined an Chinese Pinyin phrase ct as %yyyy%-%MM%-%dd% %HH%:%mm%:%ss% -0400 in Microsoft Pinyin Input Methods1 according to walterlv’s blog2. However, this method has two problems:

  1. The time zone information, i.e., zero UTC offset3 -0400 is fixed, because this is no way, like using variables in %yyyy%-%MM%-%dd% %HH%:%mm%:%ss%, to obtain this information from Windows system in Microsoft Pinyin Input Method. So, if I move to another time zone, I need to modify this self-defined phrase again.
  2. As reported in walterlv’s blog2 (actually I ever found this bug before), once above phrase ct is defined with time variables, if I edit this phrase next time, variables won’t work any more — it will become a fixed time — I need to redefine this phrase using variables again.

Today (2:00 am, Sunday, November 2, 2025), the time of NY state changed from EST to EDT, i.e., 1 hour backward34; I have to modify the UTC offset from -0400 to -0500 accordingly, so above two problems annoyed me again.

As mentioned, actually there is no a variable corresponding to UTC offset in MS Pinyin input, so I have to find another method. Finally, I decided to use software AutoHotkey5.

A Reddit user provides such a way6, i.e., using a shortcut key Win+; to input the timestamp:

1
2
3
#;::{
    SendText(FormatTime(,"ShortDate"))
}

Or,

1
2
3
#;::{
    SendText(FormatTime(,"yyyy-MM-dd HH:mm:ss"))
}

(btw, this is an AutoHotkey v2.0 script.) where the FormatTime function7 is used to input current time using a certain time form. However, again, the FormatTime per se doesn’t support UTC offset. Then, I found a very elegant way to add offset (other methods I found are much more complicated and I couldn’t understand)8:

1
2
3
4
5
6
7
8
9
10
11
^!v::
FormatTime, CurrentDateTime,, dd/MM/yyyy - hh:mm:ss
time:=A_Now 
EnvSub, time, A_NowUTC, Hours
SendRaw Jitendra - %CurrentDateTime%(GMT
if time>0
sendraw +%time%
if time<0
sendraw %time%
sendraw )
Return

which uses current local time time minus UTC time A_NowUTC to obtain the offset (and return it to) time in format Hours, and then display it using text after some post-procession. Next, I used ChatGPT to simplify it as:

1
2
3
4
5
6
7
8
9
10
11
12
13
#;::
FormatTime, CurrentDateTime,, yyyy-MM-dd HH:mm:ss
time:=A_Now 
EnvSub, time, A_NowUTC, Hours

sign := (time >= 0) ? "+" : "-"
absH := Abs(time)
hh   := (absH < 10) ? "0" . absH : absH
tz   := sign . hh . "00"

textInfo := CurrentDateTime . " " . tz
SendInput {Text}%textInfo%
Return

Note: This is a v1.1 version script, and we should download AutoHotkey v1.1 although it is deprecated.

At this time, if I use shortcut key Win+;, I’ll get:

1
2025-11-02 13:37:04 -0500

Beautiful!

There are two points should be noted:

  1. In the second line, note there are two commas between CurrentDateTime and yyyy-MM-dd HH:mm:ss, because time format is the third parameter of FormatTime function;
  2. At last, use {Text} to output timestamp in pure text. Otherwise, if I use Win+; under the Pinyin input method, the colon will be full-width (Chinese colon).


References