Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set time in php to 00:00:00

Tags:

php

time

I need to display the time but it must start from 00:00:00? I've got the following but it uses the current time.

print(date("H:i:s"));
like image 240
Wilest Avatar asked Oct 14 '11 13:10

Wilest


1 Answers

As an alternative to mktime(), try the newer DateTime class, eg

$dt = new DateTime;
$dt->setTime(0, 0);
echo $dt->format('H:i:s');

// Add one hour
$dt->add(new DateInterval('PT1H'));
echo $dt->format('H:i:s');

Update

The flexibility of DateInterval makes this a very good candidate for a timer, eg

// add 2 years, 1 day and 9 seconds
$dt->add(new DateInterval('P2Y1DT9S'));
like image 92
Phil Avatar answered Sep 22 '22 06:09

Phil