我使用Angular 5。
我将字符串转换为日期。
我的代码是:
const start_date = '2015-02-03';
const startDate = new Date(start_date);
console.log(startDate);
console.log(startDate.getDate()); // startDate.getDate() is my target
此代码的输出是:
Mon Feb 02 2015 19:00:00 GMT-0500 (Eastern Standard Time)
2
但我想得到3
结果。
不使用时区怎么解决?
很简单。
尝试这样:
const start_date = '2015-02-03';
const startDate = new Date(start_date + ' 00:00:00');
console.log(startDate);
console.log(startDate.getDate());
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句