Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 277

PostPosted: 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.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: 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
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: 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
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 277

PostPosted: Sat Dec 29, 2007 3:44 pm   
 
Thanks lots!!
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net