How do i get the current Hour and Minutes on a users PC as separate values in PHP and echo them separately?
I want to echo the hour and minute that is current in different locations.
Thanks!
edit: Since we cant do the user time, lets do server time.
12 hour clock
<?php echo date("g"); echo date("i");?>
24 hour clock w/o leading zero
<?php echo date("G"); echo date("i");?>
24 hour clock w/ leading zero
<?php echo date("H"); echo date("i");?>
Your best resource is the PHP.net manual: http://php.net/manual/en/function.date.php
$dt = new DateTime();
echo $dt->format('H');
echo $dt->format('i');
Well it's easy
echo date('H'); // is current hour 24 hour clock
echo date('h'); // is current hour 12 hour clock
echo date('ha'); // is current hour 12 hour clock with am/pm
echo date('i'); // is current minute
Results are if time is 19/06/2015 18:54:40
18
06
06pm
54
date("H") - for hour (00-23); date("i") - for minute (00 - 59)
When using a Time Zone you can use this
<?php
date_default_timezone_set("America/New_York");
echo "Today is : " . date("Y/m/d") . "<br>";
echo "The time is in New York: " . date("h:i:sa");
?>
OUTPUT
Today is : 2015/06/19
The time is in New York: 03:06:30pm
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.