I have a date object in javascript that goes as follows:
var date = 2014-12-01T00:00:00.000Z
And if I do:
var date = new Date(date);
date.setUTCMonth(date.getUTCMonth()+1);
Then the toISOString() method shows the expected value:
2015-01-01T00:00:00.000Z
But when I send that date time string through a POST to a PHP script and parse it back to a date using the DateTime class, I get this:
2014-12-31 19:00:00 -0500
I have tried setting the timezone using the DateTimeZone class and setting the timezone to my own and UTC without luck:
new DateTime($_POST['DateTime'],new DateTimeZone('America/Mexico_City'));
new DateTime($_POST['DateTime'],new DateTimeZone('UTC'));
Is there a way to set the timezone in javascript, using the Date class? Is there another way to work around this? I have small if not zero experience at all dealing with timezones.
Update:
Here's my ISO-formatted time string as per the toISOString() method (javascript):
2014-09-01T00:00:00.000Z
And here are the contents of my $_POST var as per print_r():
Array (
[DateTime] => 2014-09-01T00:00:00.000Z
)
Here's the output of my formatter function, using the '%c' format (es_MX locale):
dom 31 ago 2014 19:00:00 CDT
And the mentioned formatter function:
function formatDate($date) {
return utf8_encode(strftime('%c', $date->getTimestamp()));
}