【发布时间】:2018-11-29 17:45:05
【问题描述】:
我使用 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。
如何在不使用时区的情况下解决这个问题?
【问题讨论】:
-
如果你想要的只是日期,那么
+start_date.slice(-2)可以在没有内置解析器的变幻莫测和更少的代码的情况下完成这项工作。 ;-)
标签: javascript angular typescript date