php - strtotime and date returning incorrect date -
i'm not sure i'm doing wrong here when convert date string strtotime & better formatted date string, date wrong:
2015-03-20t20:00:00-0600 | saturday mar 21, 2015 02 00:am
on left input variable & on right output of following code:
<?php $eventdate = '2015-03-20t20:00:00-0600'; $originaltime = $eventdate; $eventdate = date('l m j, y h i:a', strtotime($eventdate)); ?> date: <?php echo $originaltime;?> | <?php echo $eventdate; ?> the correct output should friday march 20th, 2015 8:00pm
it's correct. -0600 part says input string 6 hours earlier system time, php adds 6 hours gives mar 21, 2015 02 00:am.
to right date , time, use date_default_timezone_set() function. me be:
date_default_timezone_set("europe/amsterdam"); this should convert time utc local time. if doesn't work you, can use strstr():
$eventdate = strstr($eventdate, '+', true); if ($eventdate === false) { $eventdate = $originaltime; }
Comments
Post a Comment