Question

I use the AngularUI datepicker, it works great.

The only problem is when I select a day such as 2014/05/14, the value sent is Wed May 14 2014 00:00:00 GMT+0200 (CEST).

I sent the value in ajax through $http({ ... }) and I get the value in a PHP function.

<?php 
  echo $day; //2014-05-13T22:00:00.000Z
?>

The result is : 2014-05-13T22:00:00.000Z

I would like : 2014-05-14 00:00.00

I don't understand, how to solve that ?

Was it helpful?

Solution

The datepicker will create a timezone local Date object, transforming it to JSON for sending it will convert it to UTC, thus rolling back your 2 hours of GMT+2 over the dateline.

Working with Date can be a bit tricky, I suggest looking into libraries like Moment.js to be on the safe side when transforming dates and times. By this you can freely define the format of your desired output string.

See also: How to send AngularStrap datepicker value without timezone?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top