Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
13
rated 0 times [  14] [ 1]  / answers: 1 / hits: 22257  / 10 Years ago, thu, february 5, 2015, 12:00:00

I'm utterly stuck trying to make php api exchange dates with angular frontend.



From PHP to JS I seem to have it sorted. Since Laravel handles dates through Carbon I just added CarbonCarbon::setToStringFormat('c'); to app.php which makes dates come out in ISO 8601.



PHP example:




2015-02-04T00:53:51+02:00




AngularJS date filter also seems to understand this format well and even reads the timezone correctly.



What I have yet to get working is posting JS date objects back to PHP api.



JS example:




2015-02-05T13:00:00.000Z




Javascript date format ends up with milliseconds added to the string and in default configuration Carbon complains about trailing data.



Also browsers seem to automatically translate my dates into UTC time.



Manually using new Carbon('jsDateString') seems to work at first but on closer inspection timezone data is not considered.



So my question is what would be the best and most automatic solution to send dates back to Laravel php api from AngularJS frontend?


More From » php

 Answers
153
$dt = Carbon::now();
echo $dt->toW3cString(); // 2015-02-05T14:50:55+01:00


since carbon can print it it can also parse this format



Carbon::parse('2015-02-05T14:50:55+01:00');


in javascript with moment.js momentjs.com



moment().format(); // 2015-02-05T14:50:55+01:00

[#67937] Tuesday, February 3, 2015, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
micah

Total Points: 295
Total Questions: 104
Total Answers: 92

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
;