Solved

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

Posted on 2013-01-08
2
546 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve 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…
The viewer will learn how to count occurrences of each item in an array.

680 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