|
Loftaris Adept
Joined: 24 Aug 2004 Posts: 277
|
Posted: Tue Dec 25, 2007 2:33 am
Convert seconds |
I'm trying to find a way to convert a given number of seconds into D:H:M:S format. Is there an easy way to do this without a whole lot of calculations? I was hoping I could use %time(1800:s) into 30minutes...
Anyone know how? or does anyone have a good way to calculate it and move it into the format I'm looking for?
thanks all. |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Tue Dec 25, 2007 7:08 am |
You'd use %mod with this:
Say your seconds total 191242. This is what it'd look like:
Code: |
#SHOW %eval(191242/86400) days %mod(191242/3600,24) hours %mod(191242/60,60) minutes %mod(191242,60) seconds. |
That will show:
Code: |
2 days 5 hours 7 minutes 22 seconds |
Hope this helps!
Charneus |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Tue Dec 25, 2007 5:42 pm |
#function @SecondsToLongTime() {%if(%isnum(%1),%eval(191242/86400) days %mod(191242/3600,24) hours %mod(191242/60,60) minutes %mod(191242,60) seconds,ERROR: argument passed must be a number!)}
I didn't test that, so you might need to properly wrap the eval and string labels in a %concat(). |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue Dec 25, 2007 8:00 pm |
Your code works fine, Matt, except the final implicit error string causes a syntax error because of the exclamation mark.
#function SecondsToLongTime {%if( %isnum( %1), %eval( %1/86400) days %mod( %1/3600, 24) hours %mod( %1/60, 60) minutes %mod( %1, 60) seconds, ERROR: argument passed must be a number)}
is working fine. |
|
|
|
Loftaris Adept
Joined: 24 Aug 2004 Posts: 277
|
Posted: Sat Dec 29, 2007 3:44 pm |
Thanks lots!!
|
|
|
|
|
|