pickab00's avatar

How to get PHP Timestamp on JS

I want the formatting to be similar to this:

2018-02-09 00:00:00

0 likes
5 replies
arukomp's avatar

Use Carbon.

If it's already a Carbon datetime instance (like the model timestamps created_at and updated_at, you can do this:

$dt->format('Y-m-d H:i:s');

If it's not a Carbon instance, try this:

Carbon::parse($timestamp)->format('Y-m-d H:i:s');
pickab00's avatar

@arukomp I should have provided more info

Here is my JS:

document.getElementById("date").value = i-need-to-fill-this-part;

Not sure how i should continue from here.

topvillas's avatar

Forget Carbon. Use Moment if you want to muck about with dates in JS.

pickab00's avatar

Nice. Moment worked just fine. Thanks

Please or to participate in this conversation.