denvar Posted May 24, 2008 Posted May 24, 2008 I have seen and tried functions like _Now() and _Date_Time_GetLocalTime() and _Date_Time_SystemTimeToArray() however these return the time in 24 hour format. (So 4:05pm instead of 16:05) Any ideas?
Paulie Posted May 24, 2008 Posted May 24, 2008 I'm not sure whether you want 24 hour format or not, For me doing this: #include <date.au3> MsgBox(0,"",_Now()) Returns this: 5/24/2008 12:17:15 AM If this were 24-hour format it would say 00:17:15 i believe Abryce 1
Muchuchu Posted May 24, 2008 Posted May 24, 2008 It's returning a regular 12 hour format for me as well Paulie.
denvar Posted May 24, 2008 Author Posted May 24, 2008 Sorry not all of my text was added to the message. I am looking for the current time in 12 hour format, without the date
Xenobiologist Posted May 24, 2008 Posted May 24, 2008 #include<Date.au3> ConsoleWrite(_NowTime() & @CRLF) Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
denvar Posted May 24, 2008 Author Posted May 24, 2008 hmm i wonder how I missed this in the helpfile when looking at _Now.. Thanks
denvar Posted May 24, 2008 Author Posted May 24, 2008 Is it possible using _NowTime to return only time in hour and minutes? The helpfile seems to be referring to dates not times so is confusing, can only see using $sType = 4 however that displays 24 hour format Am trying to achieve : 5:15 pm for example
Paulie Posted May 24, 2008 Posted May 24, 2008 (edited) You can always just do #include <date.au3> MsgBox(0,"", StringTrimRight(_NowTime(),6)&StringRight(_NowTime(),3)) It's roundabout, but it works i guess Edited May 24, 2008 by Paulie
aslani Posted May 24, 2008 Posted May 24, 2008 (edited) Or MsgBox(0,"", _TimeHrMin()) Func _TimeHrMin() $hr = @HOUR If $hr > 12 Then $hr = $hr -12 $x = "PM" Else $x = "AM" EndIf $time = $hr & ":" & @MIN & " " & $x Return ($time) EndFunc EDIT: Added the AM and PM Edited May 24, 2008 by aslani [font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version
ResNullius Posted May 24, 2008 Posted May 24, 2008 (edited) How about:MsgBox(0, "", _AmPmTimeIs()) Func _AmPmTimeIs() $ampm = "am" $Hour = @HOUR If $Hour > 12 Then $Hour -= 12 $ampm = "pm" EndIf $Min = @MIN $time = $Hour & ":" & $Min & " " & $ampm Return $time EndFuncEdit: aslani sorta beat me to it, but mine adds the am/pm indicator Edit 2:hey aslani, we gotta stop posting/editing at the same time Edited May 24, 2008 by ResNullius
Valuater Posted May 24, 2008 Posted May 24, 2008 Or MsgBox(0,"", _TimeHrMin()) Func _TimeHrMin($sType = 3) $hr = @HOUR If $hr > 12 Then $hr = $hr -12 EndIf $time = $hr & ":" & @MIN Return ($time) EndFuncoÝ÷ Ûú®¢×µÓ~¬O*^ 8)
denvar Posted May 24, 2008 Author Posted May 24, 2008 Thanks for the input guys. Using Valuater's code and it seems to be working a charm, was hoping would have been a simpler way to do this, woyld have though h:mm am/pm would be more commonly required then h:mm:ss Anyway alls well that ends well, thanks guys
ProgAndy Posted May 24, 2008 Posted May 24, 2008 (edited) Is this right? CODESelect Case @HOUR = 0 And @SEC=0 And @MIN=0 $hour = 12 $AMPM = "a.m." Case @HOUR = 12 And @SEC=0 And @MIN=0 $hour = 12 $AMPM = "p.m." Case @HOUR > 11 $hour = @HOUR - 12 $AMPM = "p.m." Case Else $hour = @HOUR $AMPM = "a.m." EndSelect $time12 = StringFormat("%02d:%02d:%02d %s",$hour,@MIN,@SEC,$AMPM) MsgBox(0, '', $time12) Btw: 12 noon = 12:00 PM ....... 12 midnight = 12:00 AM //Edit: Oh, no forgot to reload Edited May 24, 2008 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
GEOSoft Posted May 24, 2008 Posted May 24, 2008 @Val Funny thing, I have that exact code written in one of my funcs and I suspect others do as well. The only diff that I see is I have a leading space in $ampm for readability. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
denvar Posted May 24, 2008 Author Posted May 24, 2008 @Val I have just noticed 12 is not handled correctly, for instance 12:05 in the afternoon is being shown as am not pm
aslani Posted May 24, 2008 Posted May 24, 2008 $sType = 3 ??huh? what? @HOUR can be a "0" ZeroThat's right, my bad [font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version
aslani Posted May 24, 2008 Posted May 24, 2008 (edited) @Val I have just noticed 12 is not handled correctly, for instance 12:05 in the afternoon is being shown as am not pm Try this MsgBox(0,"", _TimeHrMin()) Func _TimeHrMin() $hr = @HOUR If $hr <> 12 Then If $hr > 12 Then $hr = $hr -12 $x = "PM" Else $x = "AM" EndIf Else $x = "PM" EndIf $time = $hr & ":" & @MIN & " " & $x Return ($time) EndFunc Edited May 24, 2008 by aslani [font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version
denvar Posted May 24, 2008 Author Posted May 24, 2008 (edited) @Aslani Noon would lead to x not being declared This is solved with Func _TimeHrMin() $hr = @HOUR If $hr <> 12 Then If $hr > 12 Then $hr = $hr -12 $x = "PM" Else $x = "AM" EndIf Else $x = "PM" EndIf $time = $hr & ":" & @MIN & " " & $x Return ($time) EndFunc //Edit : beat me to it Edited May 24, 2008 by denvar
denvar Posted May 24, 2008 Author Posted May 24, 2008 (edited) Also to keep in tune with standards midnight ($hr = 0) should be shown as 12 am instead of 00 am Func _TimeHrMin() $hr = @HOUR If $hr <> 12 Then If $hr > 12 Then $hr = $hr -12 $x = "PM" ElseIf $hr = 0 Then $hr = 12 $x = "AM" Else $x = "AM" EndIf Else $x = "PM" EndIf $time = $hr & ":" & @MIN & " " & $x Return ($time) EndFunc Edited May 24, 2008 by denvar
GEOSoft Posted May 24, 2008 Posted May 24, 2008 @ProgAndy You don't need the last part of the lines containing And @SEC=0 And @MIN=0 All you need is Case @Hour = @Sec and @Min are being handled later anyway. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now