lundi 18 novembre 2019

Convert JavaScript Time to PHP with Laravel Carbon

I am developing a website with Angular 8 as front end and Laravel(version:5.8.*) as back end. I want to store date selected by user in MySQL database. Posting the selected date by user as 2019-11-19T02:30:14.000Z. In app.php timezone has been declared as 'Asia/Kolkata'. I want to convert the js date to PHP date with specified timezone. In my controller :

$date_no_timezone=date('Y-m-d H:i:s',strtotime($request->from_time);
$date_with_timezone=\Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $date_no_timezone,'Asia/Kolkata');

But it doesn't return anything, showing 500 error. NB: Iam a beginner in Laravel.

How can I do this task?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire