Solved

How to get days, hours, minutes, seconds from a large seconds value.

Posted on 2013-01-08
2
545 Views
Last Modified: 2013-12-25
$num_of_seconds = 172870;

#how to get dd days, hh hours, mm minutes, and ss seconds?  So it will be like 2 days 0 hours 1 minutes 10 seconds.
0
Comment
Question by:rgbcof
2 Comments
 
LVL 31

Accepted Solution

by:
farzanj earned 500 total points
ID: 38757552
my $num_of_seconds = 172870;
my $dd = int($num_of_seconds / 86400);
my $hh = int(int(($num_of_seconds % 86400)) / 3600);
my $mm = int(int(($num_of_seconds % 86400) % 3600) /60);
my $ss = int(int(($num_of_seconds % 86400) % 3600) %60);

Open in new window

0
 
LVL 84

Expert Comment

by:ozo
ID: 38758077
#or
my $num_of_seconds = 172870;
my($ss,$mm,$hh,$dd)=(gmtime $num_of_seconds)[0,1,2,7];   #but this only works up to 364 days
#the simplest way to extend it beyond 364 days may be to add another variable.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question