midday.ahk

Converts 24-hour (military) time string to 12-hour (meridiem) time string and vice versa.

Usage no npm install needed!

<script type="module">
  import middayAhk from 'https://cdn.skypack.dev/midday.ahk';
</script>

README

midday.ahk

Converts 24-hour (military) time string to 12-hour (meridiem) time string and vice versa.

Installation

In a terminal or command line navigated to your project folder:

npm install midday.ahk

In your code only export.ahk needs to be included:

#Include %A_ScriptDir%\node_modules
#Include midday.ahk\export.ahk

midday := new midday()
result := midday.to24("12:30 AM")
; => "00:30"

result := midday.to12("00:30")
; => "12:30 AM"

You may also review or copy the library from ./export.ahk on GitHub; #Incude as you would normally when manually downloading.

API

.to12(value)

Converts 24-hour (military) time string to 12-hour (meridiem) time string.

Arguments

time (String): the time string

Returns

time (String): converted 24-hour time string to 12-hour time

Exception

throws an error if the time string is invalid

midday.to24("12:30 AM")
; => "00:30"

.to24(value)

Converts 12-hour (meridiem) time string to 24-hour (military) time string.

Arguments

time (String): the time string

Returns

time (String): converted 24-hour time string to 12-hour time

Exception

throws an error if the time string is invalid

midday.to12("00:30")
; => "12:30 AM"

midday.to12("0030")
; => "12:30 AM"