Solved

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

Posted on 2013-01-08
2
541 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
Comment Utility
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
Comment Utility
#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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now