首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React-datepicker选定的日期格式

React-datepicker选定的日期格式
EN

Stack Overflow用户
提问于 2021-10-19 10:14:11
回答 1查看 57关注 0票数 0

当前日期格式: 2021-04-30T23:00:00.000Z

尝试过但没有成功的方法(new Date(startDate) new Date(startDate).toLocaleDateString()

错误

代码语言:javascript
复制
RangeError: Invalid time value

var originalDate = toDate(dirtyDate);
  
  if (!isValid(originalDate)) {
   throw new RangeError('Invalid time value');
    } // Convert the date in system timezone to the same date in UTC+00:00 timezone.
     // This ensures that when UTC functions will be implemented, locales will be compatible with them.
     // See an issue about UTC functions: https://github.com/date-fns/date-fns/issues/376
EN

回答 1

Stack Overflow用户

发布于 2021-10-19 10:19:32

这是一个ISO-8601日期表示,您可以通过将其传递到Date构造函数并在对象上调用像getURChours()这样的函数来转换它

代码语言:javascript
复制
let date = new Date('2021-04-30T23:00:00.000Z');
console.log(date.getUTCHours()); // Hours
console.log(date.getUTCMinutes()); // Minutes
console.log(date.getUTCSeconds()); // Seconds

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69629011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档