php - date_create_from_format is returning wrong day -


i facing issue date_create_from_format php. here code:

date_default_timezone_set('asia/kathmandu'); $date = date_create_from_format('d/m/y h:ia', '28/05/2016 15:24pm'); echo date('d/m/y h:ia',$date->gettimestamp()); //returns 29/05/2016 03:24am 

i trying change 24 hour time 12 hour. working.thanks.

you must create date 1 type. use pm-am or 24h format. otherwise 15:43 pm = 12:43 pm + 3 hour.

try this:

$date = date_create_from_format('d/m/y h:i', '28/05/2016 15:24'); 

update

if not control input data, can use crutch:

$date = date_create_from_format('d/m/y h:i', substr('28/05/2016 15:24pm', 0, -2)); 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -