Time in mysql is stored like this
2022-04-25 11:03:20
but when it is showed on client with vuejs i am getting this as response
2022-04-25T09:03:20.000Z
How do i show it as it is shown in db?
CodePudding user response:
The date you're getting is in ISO-8601 format. You'll want to continue to store it like that so you've got the timezone (as denoted by the suffix 'Z'). In your frontend, it's easy to convert the date into any format you like.
For example, based on your example, you can use:
const dateFromDb = '2022-04-25T09:03:20.000Z';
const dateForUi = new Date(dateFromDb).toLocaleString('nl-NL');
console.log(dateForUi); // 25-4-2022 10:03:20
You can also convert any date object back into ISO format, using .toISOString()
.
There's also many other date formatting methods (outlined in the Date()
docs), or for more advanced date / time operations there are libraries like moment.js