【问题标题】:React-datepicker selected date formatreact-datepicker 选择的日期格式
【发布时间】:2021-12-06 06:32:44
【问题描述】:

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

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

错误

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

【问题讨论】:

    标签: javascript reactjs date datetime react-datepicker


    【解决方案1】:

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

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-29
      • 2018-10-23
      • 2014-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-22
      相关资源
      最近更新 更多