The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Ticks in seconds. mig28mx HP-UX 1 06-26-2007 05:43 PM
is there any way to excute script every N seconds? umen Shell Programming and Scripting 7 03-30-2006 01:06 AM
getting time in mili seconds Bhups UNIX for Dummies Questions & Answers 5 12-06-2005 07:34 AM
Get lines in 5 seconds Lestat Shell Programming and Scripting 16 06-20-2005 01:24 PM
how to get number of seconds captainzeb UNIX for Advanced & Expert Users 2 12-02-2003 03:12 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-19-2005
Registered User
 

Join Date: Sep 2005
Posts: 36
seconds to hh:mm:ss

Any sleek way to convert seconds to hh:mm:ss format .
I know it can be done by mod and divide . Looking for a one liner if possible .

Example
3600 seconds = 01:00:00
3601 seconds = 01:00:01
Reply With Quote
Forum Sponsor
  #2  
Old 10-19-2005
vertigo23's Avatar
Registered User
 

Join Date: Jul 2005
Location: SF, CA
Posts: 67
Perl solution

Dunno if it's the most concise, but it's what I came up with. Fun problem

Code:
#!/usr/bin/perl -w

$si=$ARGV[0];

$s=$si%60;
$m=(($si%3600)-$s)/60;
$h=$s/3600;
$h=~s/^(\d+).*/$1/;

print "$h:$m:$s\n";
Should be easy to turn that into a 1-liner.

Last edited by vertigo23; 10-19-2005 at 11:24 AM. Reason: typoes
Reply With Quote
  #3  
Old 10-19-2005
Registered User
 

Join Date: Sep 2005
Posts: 36
That's what I am doing using shell .Certainly not in this concise manner .Thanks for this .

My purpose was just to explore if I am missing something
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:17 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0