0

My backend is sending me a time like this:

$date = Carbon::now()->format('m-d-Y H:i:s')

the value of $date is a string like "01-21-2021 15:25:06"

Can I use that to create a Date object in Javascript?

0

2 Answers 2

1

Not directly, a simple format change is all that is required:

const dateString = "01-21-2021 15:25:06";

console.log(new Date(dateString.replace('-','/')).toLocaleString());

Sign up to request clarification or add additional context in comments.

Comments

0

You can probably use JavaScript's Date.parse() function to do this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse#description

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.