JS processes the time string from the backend, expressed as YYYY-MM-DD HH:mm:ss format

Problem description: Because the backend is in JSON, the received time format is a string

Solution: So first use var to receive a Date type parameter, and then use various get methods to get each field

obj.loginDate is a string of stored standard time

var obj=JSON.parse(localStorage.getItem("userInfo"));
var logintime = new Date(obj.loginDate);
var month= logintime.getMonth()+1;
this.loginData = logintime.getFullYear()+"年"+month+"月"+logintime.getDate()+"日"+logintime.getHours()+"时"+logintime.getMinutes()+"分";

loginData sample outputInsert picture description here

Guess you like

Origin blog.csdn.net/qq_41170600/article/details/108735635