Last active
October 3, 2017 11:47
12 hour to 24 hour format in AutoIt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; #FUNCTION# ==================================================================================================================== | |
; Name ..........: ConvertTime12To24 | |
; Description ...: Converts 12 hour time to 24 hour time, made while keeping _DateDiff's format in mind :) | |
; Syntax ........: ConvertTime12To24($sTime, $sPeriod[, $sDelimiter = ':']) | |
; Parameters ....: $sTime - Timestamp. (Can be a single digit or a pattern like H:M:S) | |
; $sPeriod - AM or PM. | |
; $sDelimiter - [optional] Separator between units of time. Default is ':'. | |
; Return values .: $sTime in 24 hour format with 0 padding | |
; Author ........: Damon Harris (TheDcoder) | |
; Remarks .......: Ensures that the first 3 parts have 0 padding if the time unit is single digit (Example 09 instead of 9) | |
; Link ..........: https://git.io/vdWnY | |
; Example .......: ConvertTime12To24('8:07:22', 'PM') | |
; =============================================================================================================================== | |
Func ConvertTime12To24($sTime, $sPeriod, $sDelimiter = ':') | |
$aTime = StringSplit($sTime, ':') | |
For $iElement = 1 To ($aTime[0] > 3 ? 3 : $aTime[0]) | |
$aTime[$iElement] = StringFormat('%.2i', Number($aTime[$iElement])) | |
Next | |
If $sPeriod = 'PM' Then $aTime[1] = StringFormat('%.2i', Number($aTime[1]) + 12) | |
Return _ArrayToString($aTime, $sDelimiter, 1) | |
EndFunc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment