Not sure what I am doing wrong. I have a laravel 8 application where I am storing my time in UTC with timestamp_no_timezone in postgresql. When I view the time in the database it is showing today's date with 13:45 as the time. When I use vue-moment and display the time with the timezone set to America/New_York it is still showing 1:45 PM and it should be 8:45 AM with the offset. What could I be missing? I have even done a console.log of the timezone from moment and it is showing America/New_York.
This is the expression that I am using:
{{ [ timesheet.start, "YYYY-MM-DD HH:mm:ss" ] | moment("timezone", "America/New_York", "h:mm A") }}
Convert the stored dateTime to epoch while sending in response.
How you can convert dateTime to epoch there are many ways(send dateTime in epoch in response).
Add in your Model
protected $casts = ['datetime_field' => 'timestamp']
add this method in Laravel class from where you are sending response
protected function toEpoch($datetime )
{
if (gettype($datetime) == 'string') {
$datetime = new DateTime($datetime);
return Carbon::instance($datetime)->format('U');
} else if ($datetime instanceof Carbon) {
return $datetime->format('U');
} else if ($datetime != null) {
return Carbon::instance($datetime)->format('U');
}
}
}
In vue project
{{new Date(epoch*1000)}}