1๐
// Just pass string to new Date method
const customDate = new Date("2022-02-22T06:02:53.585764600Z");
// Test
console.log(customDate.getHours());
- [Vuejs]-Blockly can console.log but can't interact with the workspace when using Vue.js
- [Vuejs]-Laravel Broadcasting Private Channel โ broadcasting/auth error 500
0๐
I already found the answer for my problem,
{{Date($store.state.user.lastLogin)}}
Just use this to cast the string inside the brackets
0๐
A possible solution is that you can pass the string date from the backend into a Date object. And only then you will be able to use Date methods.
or in your case
{{Date{$store.state.user.lastLogin}}
Please refer to the attached code as a reference.
//Value from DB
const strDate = "2022-02-22T06:02:53.585764600Z";
//Parse the date
const parsedDate = new Date(strDate);
document.querySelector("#display-date").textContent = parsedDate.getHours();
<h1 id="display-date"></h1>
MDN Date docs: Date
W3schools Date Objects
- [Vuejs]-Rails System Test Not Loading Vue
- [Vuejs]-How to display a single record in database using Laravel and vue js?
Source:stackexchange.com