I am using following function and I want time in 24hr clock format but this gives me time in 12hrs:
<?php
date_default_timezone_set('Asia/Kolkata');
$timestamp = date("d/m/Y h:i:s", time());
print $timestamp ;
?>
What am I doing wrong?
For example if the time in 12 hour clock is 11:00 PM, then the time in 24 hour clock is 11:00 + 12:00 = 23:00 hours. Q.
php //current Date, i.e. 2013-08-01 echo date("Y-m-d"); //current Time in 12 hour format, i.e. 08:50:55pm echo date("h:i:sa"); //current Time in 24 hour format, i.e. 18:00:23 echo date("H:i:s"); //current Month, i.e. 08 echo date("m"); //current Month name, i.e. Aug echo date("M"); ?>
In Windows, click the Start button. Click Control Panel, and then click Clock, Language, and Region. Under Regional and Language, click Change the date, time, or number format.
From the docs for date()
: The H
format character gives the hour in 24h format. Also, you can use G
if you do not want the leading 0
for hours before noon.
Examples (if current time was seven-something-AM)date('H:i:s')
-> "07:22:13"date('G:i:s')
-> "7:22:13"
For your specific case:
$timestamp = date("d/m/Y H:i:s", time());
According to the manual the difference is in the capitalization of hour portion: "h" returns a 12-hour format of an hour with leading zeros, 01 through 12. "H" returns a 24-hour format of an hour with leading zeros, 01 through 23.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With