将日期字符串转换为Date对象

时间:2020-01-14 20:29:27

标签: javascript

当我使用

var today = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate());

我知道todayTue Jan 14 00:00:00 GMT+02:00 2020

如果我做today.toDateString(),那么我会得到Tue Jan 14 2020

如果将最后一个结果存储到单元格中,如何将其转换回原来的状态? (Date个对象)

2 个答案:

答案 0 :(得分:1)

尝试如下,

...
FROM wp_users u 
LEFT JOIN wp_usermeta ma ON u.ID = ma.user_id AND ma.meta_key = 'Address'
LEFT JOIN wp_usermeta mm ON u.ID = mm.user_id AND mm.meta_key = 'mobile_number'
LEFT JOIN wp_usermeta mp ON u.ID = mp.user_id AND mp.meta_key = 'phone_number'
LEFT JOIN wp_usermeta mc2 ON u.ID = mc2.user_id AND mc2.meta_key = 'user_city'
LEFT JOIN wp_usermeta ms ON u.ID = ms.user_id AND ms.meta_key = 'user_state'
LEFT JOIN wp_usermeta mz ON u.ID = mz.user_id AND mz.meta_key = 'user_zip'
...

答案 1 :(得分:1)

是的,有4种方法可以在JavaScript中创建新的Date对象:

  1. new Date()
  2. new Date(year, month, day, hours, minutes, seconds, milliseconds)
  3. new Date(milliseconds)
  4. new Date(date string)

最后一个解决您的问题:

let now = new Date();
let today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
console.log(today);
let today2 = new Date(today.toString());
console.log(today2);