| View previous topic :: View next topic |
| Author |
Message |
Andre
Joined: 22 Jul 2005 Posts: 52
|
Posted: Tue Jan 03, 2006 10:09 am Post subject: TimeToStr |
|
|
Hi,
hase someone made an TimeToStr function
Example : TimeToStr(120)
will result :00:02:00
Andre |
|
| Back to top |
|
 |
Andre
Joined: 22 Jul 2005 Posts: 52
|
Posted: Tue Jan 03, 2006 2:51 pm Post subject: |
|
|
Got it myself by looking on on the forum ....
| Code: |
TimeLog(T1)
{
transform,S,MOD,T1,60
stringlen,L1,S
if L1 =1
S=0%S%
if S=0
S=00
M1 :=(T1/60)
transform,M2,MOD,M1,60
transform,M3,Floor,M2
stringlen,L2,M3
if L2 =1
M3=0%M3%
if M3=0
M3=00
H1 :=(M1/60)
transform,H2,Floor,H1
stringlen,L2,H2
if L2=1
H2=0%H2%
if H2=0
H2=00
result= %H2%:%M3%:%S%
return result
}
|
|
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4078 Location: Pittsburgh
|
Posted: Tue Jan 03, 2006 4:08 pm Post subject: |
|
|
| FormatTime provides a simpler solution. |
|
| Back to top |
|
 |
Andre
Joined: 22 Jul 2005 Posts: 52
|
Posted: Wed Jan 04, 2006 7:02 am Post subject: |
|
|
Laszlo,
could u provide an example, can't seem to fix it.
Andre |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Wed Jan 04, 2006 8:25 am Post subject: |
|
|
Hi, this is a mod of your code | Code: | MsgBox, % "this is the result of 7 " . TimeLog(7)
MsgBox, % "this is the result of 123 " . TimeLog(123)
MsgBox, % "this is the result of 4025 " . TimeLog(4025)
;T1 = value in seconds
TimeLog(T1)
{
SetFormat, FLOAT, 02.0
S := Mod(T1,60) + 0.0
M := Mod((T1-S)/60,60)
H := ((T1-S)/60 - M)/60
return H . ":" . M . ":" . S
} |
@Laszlo: I do not see how to use FormatTime as well. Hope you can share some wisdome. _________________ Ciao
toralf  |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10480
|
Posted: Wed Jan 04, 2006 1:31 pm Post subject: |
|
|
| toralf wrote: | | @Laszlo: I do not see how to use FormatTime as well. Hope you can share some wisdome. | At first I didn't see it either, but I think you could use EnvAdd to add the incoming number of seconds to midnight of any date. Something like:
| Code: | MsgBox % FormatSeconds(7384) ; 7384 = 2 hours + 3 minutes + 4 seconds, yields: 02:03:04.
FormatSeconds(NumberOfSeconds)
; Convert up to 24 hours worth of seconds into hh:mm:ss format.
{
Midnight = %A_YYYY%%A_MM%%A_DD%
Midnight += %NumberOfSeconds%, seconds
FormatTime, OutputVar, %Midnight%, HH:mm:ss ; HH yields 24-hour format.
return OutputVar
} |
But the above will only work if the incoming seconds is under less than 24 hours worth of seconds, so Toralf, your approach seems better unless someone comes up with something simpler. I'll add it to the FormatTime page as an example. |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Wed Jan 04, 2006 2:20 pm Post subject: |
|
|
Laszlo wrote: | Quote: | | FormatTime provides a simpler solution. | GO Laszlo GO (holy moly, shimanov has entered the scene ) ... |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4078 Location: Pittsburgh
|
Posted: Wed Jan 04, 2006 5:40 pm Post subject: |
|
|
...and if you want to go beyond one day | Code: | MsgBox % TimeLog(25*60*60+11*60+2)
TimeLog(Seconds)
{
time = 20000101
time+= %Seconds%, seconds
FormatTime mmss, %time%, mm:ss
FormatTime HH, %time%, HH
FormatTime dd, %time%, dd
return 24*(dd-1)+HH ":" mmss
} | but then it is not simpler than toralf's solution. Or, a hybrid: | Code: | TimeLog(Seconds)
{
time = 20000101
time+= %Seconds%, seconds
FormatTime mmss, %time%, mm:ss
return Seconds//3600 ":" mmss
} |
Last edited by Laszlo on Wed Jan 04, 2006 6:07 pm; edited 1 time in total |
|
| Back to top |
|
 |
shimanov
Joined: 25 Sep 2005 Posts: 612
|
Posted: Wed Jan 04, 2006 5:52 pm Post subject: |
|
|
| BoBo wrote: | | shimanov has entered the scene |
Fashionably late, as usual.
| Code: |
FormatSeconds( p_seconds )
{
h := p_seconds//3600
p_seconds := Mod( p_seconds, 3600 )
m := p_seconds//60
s := Mod( p_seconds, 60 )
return, Chr( 48*( h < 10 ) ) h ":" Chr( 48*( m < 10 ) ) m ":" Chr( 48*( s < 10 ) ) s
}
|
|
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4078 Location: Pittsburgh
|
Posted: Wed Jan 04, 2006 6:19 pm Post subject: |
|
|
Actually, toralf's solution can be written in just one line, with the global: | Code: | | SetFormat FLOAT, 02.0 | After that, we don't even need a function | Code: | | MsgBox % Seconds//3600. ":" Mod(Seconds//60,60.) ":" Mod(Seconds,60.) | So, he is the champ.
Edit: using decimal points in the parameter makes the results FLOAT, displayed in 02.0 format
Last edited by Laszlo on Thu Jan 05, 2006 12:40 am; edited 1 time in total |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Wed Jan 04, 2006 8:27 pm Post subject: |
|
|
I think the championship goes to you, since you were the one to find the trivial solution. :)
But I guess the original request by Andre is best answered with the functions we all provided. I is now up to him to choose which to use. _________________ Ciao
toralf  |
|
| Back to top |
|
 |
shimanov
Joined: 25 Sep 2005 Posts: 612
|
Posted: Wed Jan 04, 2006 9:04 pm Post subject: |
|
|
| toralf wrote: | | I think the championship goes to you |
Toralf, the credit is yours. Without your insight, the final solution would remain undiscovered. |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Wed Jan 04, 2006 9:12 pm Post subject: |
|
|
I disagree, since I only simplified Andres code. But thanks, you see me blush. *bow low* _________________ Ciao
toralf  |
|
| Back to top |
|
 |
shimanov
Joined: 25 Sep 2005 Posts: 612
|
Posted: Wed Jan 04, 2006 9:20 pm Post subject: |
|
|
That is certainly your right. But if you check the other codes, you will notice a marked difference, in which every other suggested solution lacked your insight. The key -- your insight -- was to perform automatic formatting using:
| Code: |
SetFormat, FLOAT, 02.0
|
|
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10480
|
Posted: Thu Jan 05, 2006 2:46 am Post subject: |
|
|
| Nice. I've added the enhanced version to the bottom of FormatTime. But I left it as a function since some people might prefer it that way. |
|
| Back to top |
|
 |
|