Page 1 of 1
How can I insert regular time?
Posted: 06 Jan 2022, 16:26
by LAPIII
My script only inserts military time:
Code: Select all
!T
FormatTime, Time,, h:mm
SendInput %CurrentDateTime%
Return
Could I also insert AM, PM, and EST.
Re: How can I insert regular time?
Posted: 06 Jan 2022, 16:39
by flyingDman
Use the time formats provide here:
https://www.autohotkey.com/docs/commands/FormatTime.htm
To determine the UTC offset (and the timezone) use this:
Code: Select all
tmdif:=a_now
tmdif+=-a_nowUTC
msgbox % tmdif
Re: How can I insert regular time?
Posted: 06 Jan 2022, 17:14
by amateur+
@LAPIII, I think, your script inserts nothing because there are two fatal mistakes in it:
![Image](https://i.ibb.co/tqcr2MR/Screenshot-13.jpg)
Re: How can I insert regular time? Topic is solved
Posted: 06 Jan 2022, 17:24
by amateur+
Code: Select all
!T::
CurrentDateTime := A_NowUTC
CurrentDateTime += -5, h
FormatTime, CurrentDateTimeESTshort, % CurrentDateTime, h:mm tt EST
SendInput %CurrentDateTimeESTshort%
Return
Re: How can I insert regular time?
Posted: 06 Jan 2022, 17:31
by TLM
Here's a trick to get your abbreviated standard name:
Code: Select all
For Item in ComObjGet( "winmgmts:\\.\root\CIMV2" ).ExecQuery( "Select * from Win32_TimeZone" )
StandardName := Item.StandardName
For Each, Word in ( StrSplit( StandardName, " " ), StandardAbrvName := "" )
StandardAbrvName .= SubStr( Word, 1, 1 )
FormatTime, CurrentDateTime, A_Now, % "h:mm tt " StandardAbrvName
SendInput %CurrentDateTime%
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
Re: How can I insert regular time?
Posted: 06 Jan 2022, 17:49
by amateur+
TLM wrote: ↑06 Jan 2022, 17:31
Code: Select all
FormatTime, CurrentDateTime, A_Now, % "h:mm tt " StandardAbrvName
Btw, it is better to put %-sign before
A_Now, b/c your great script doesn't fail in the end for only one reason: empty string or string of invalid time format are considered as %A_Now%.
Although it doesn't work for Russian locale.
Re: How can I insert regular time?
Posted: 06 Jan 2022, 18:04
by flyingDman
@TLM Nice, thank you!