Convert Seconds into Days, Hours, Minutes and Seconds

Convert seconds to days, minutes, and hours in Obj-c

In this case, you simply need to divide.

days = num_seconds / (60 * 60 * 24);
num_seconds -= days * (60 * 60 * 24);
hours = num_seconds / (60 * 60);
num_seconds -= hours * (60 * 60);
minutes = num_seconds / 60;

For more sophisticated date calculations, such as the number of days within the ten million seconds after 3pm on January 19th in 1983, you would use the NSCalendar class along with NSDateComponents. Apple's date and time programming guide helps you here.

Converting Seconds into days, hours, minutes, and seconds

Converting every variable to integer should erase decimals as you want, so use it like d = int(x/86400) for all of your variables (d, h, m and s).

Converting seconds into days, hours, minutes & seconds in Python

It looks like you're trying to do something like:

result = "time in minutes is"
if days >0:
result += f" {days} days"
if hours > 0:
result += f" {hours} hours"
if mins > 0:
result += f" {mins} minutes"
if secs > 0:
result += f" {secs} seconds"

Convert seconds to days: hours:minutes:seconds

You may try

library(lubridate)
seconds_to_period(86400)
#[1] "1d 0H 0M 0S"

seconds_to_period(48000)
#[1] "13H 20M 0S"

If you need to format

td <- seconds_to_period(86400)
sprintf('%02d %02d:%02d:%02d', day(td), td@hour, minute(td), second(td))
#[1] "01 00:00:00"

If it spans for >99 days,

td <- seconds_to_period(1e7)
sprintf('%03d %02d:%02d:%02d', day(td), td@hour, minute(td), second(td))
#[1] "115 17:46:40"

How to convert seconds into days hours minutes in Laravel

I got a solution.

$value = '90060';
$dt = Carbon::now();
$days = $dt->diffInDays($dt->copy()->addSeconds($value));
$hours = $dt->diffInHours($dt->copy()->addSeconds($value)->subDays($days));
$minutes = $dt->diffInMinutes($dt->copy()->addSeconds($value)->subDays($days)->subHours($hours));
echo CarbonInterval::days($days)->hours($hours)->minutes($minutes)->forHumans();

Updated Solution

CarbonInterval::seconds(90060)->cascade()->forHumans();


Related Topics



Leave a reply



Submit