有时候后端使用的字段为datetime,接口返回数据会变成/Date(1708311728230+0800)/这种,这时候就需要去转换一下格式 function convertDateString(dateString) { var timestamp = parseInt(dateString.match(/\d+/)[0]); var timezoneOffset = parseInt(dateString.match(/[-+]\d+/)[0]); var date = new Date(timestamp); var adjustedDate = new Date(date.getTime() + (timezoneOffset * 60 * 1000)); var year = adjustedDate.getFullYear(); var month = adjustedDate.getMonth() + 1; var day = adjustedDate.getDate(); return year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day); }
标签:adjustedDate,前端,dateString,datetime,var,格式,month,day From: https://www.cnblogs.com/SmallChen/p/18025060