We are having problems to get the datetime representation in php and momentjs in sync. Lets say we are having a datetime with a time zone in Moscow:
2013-06-10T10:40:00.000+04:00
The user should see the time in local: 2013-06-10T10:40:00. No matter if he sits in Spain or USA. Following php code would produce the proper time that we need:
$date = new DateTime('2013-06-10T10:40:00.000+04:00');
echo $date->format('d.m.Y H:i:s');
The output is:
10.06.2013 10:40:00
But if we parse the same datetime string in frontend with momentjs:
moment('2013-06-10T10:40:00.000+04:00').format('D.M.YYYY h:mm:ss');
The output is:
10.6.2013 8:40:00
The browsers time zone is Europe/Berlin (+02:00). Using utc() calculates the date the wrong way also. What we need is a local time of the place, so in case of php it is the right one. Giving a parse string to momentjs:
moment('2013-06-10T10:40:00.000+04:00', "YYYY-MM-DD HH:mm").format('D.M.YYYY h:mm:ss')
would do the trick, so the time zone is deleted. But we actually should set the parse string globally, but how?
Thanks for suggestions.