J
J
jeston2014-02-16 17:54:55
PHP
jeston, 2014-02-16 17:54:55

Time Manipulation in PHP and JS

The following happens:
1. An object is formed on the client and sent to the server via the Angula $http service:

// insert record in table
        var jsonForServer = {
            'date'    : $scope.selectedCalendarEvent,
            'typeDate': 'local',
            'events'  : $scope.userClickedEvents.fullListTitles
        };
        // save to server
                $http.post('calendar/updatedate', { calendar_record: jsonForServer })
                    .success(function(response)
                    {
                        console.log(response);
                    });

Before submitting, I make sure that the 'date' field of the jsonForServer object is set to
Mon Feb 10 2014 00:00:00 GMT+0200 by the jquery plugin, which is fine with me.
2. On the server action Yii gets something else - the previous day at 22.00. This is what var_dump($dateToInsert) shows me of what came in:
2014-02-09T22:00:00.000Z
The code that receives the request from Angular is this:
$calendar = json_decode(file_get_contents('php://input'));
$dateToInsert =  $calendar->calendar_record->date;

Here the essence of what is happening is approximately clear: on the client, the timestamp is +2 hours, and on the client -2 hours of the previous day (and always). But what comes to the server does not suit me at all, since the record I need is written to the database a day earlier, so I really would like to fix this situation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max, 2014-02-16
@jeston

Send timestamp or add two hours or set correct date_default_timezone_set

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question