iamkun / dayjs

⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
https://day.js.org
MIT License
46.66k stars 2.28k forks source link

V1.11.12 >>> ISO 8601 "YYYY-MM-DDTHH:mm:ssZ" BUG! #2712

Open gowy222 opened 3 weeks ago

gowy222 commented 3 weeks ago

dayjs: v1.11.12 nodejs: v18.18.2 win11

"use strict";
const dayjs = require("dayjs");
const dayjs_timezone = require('dayjs/plugin/timezone');
const dayjs_utc = require('dayjs/plugin/utc');
const duration = require('dayjs/plugin/duration');
const customParseFormat = require('dayjs/plugin/customParseFormat');

dayjs.extend(duration);
dayjs.extend(dayjs_utc);
dayjs.extend(dayjs_timezone);
dayjs.extend(customParseFormat);
dayjs.tz.setDefault("Asia/Shanghai");

console.log(dayjs('2024-08-19T10:30:00Z', "YYYY-MM-DDTHH:mm:ssZ", true).isValid()); => false
M {
  '$L': 'en',
  '$u': undefined,
  '$d': Invalid Date,
  '$y': 2024,
  '$M': 7,
  '$D': 19,
  '$W': 1,
  '$H': 18,
  '$m': 30,
  '$s': 0,
  '$ms': 0,
  '$x': {},
  '$isDayjsObject': true
}

console.log(dayjs.utc('2024-08-19T10:30:00Z', "YYYY-MM-DDTHH:mm:ssZ", true).isValid()); => dayjs.utc still false!
M {
  '$L': 'en',
  '$u': true,
  '$d': Invalid Date,
  '$y': 2024,
  '$M': 7,
  '$D': 19,
  '$W': 1,
  '$H': 10,
  '$m': 30,
  '$s': 0,
  '$ms': 0,
  '$x': {},
  '$isDayjsObject': true
}

exinfo: 2024: Matches YYYY, representing the year. 08: Matches MM, representing the month of August. 19: Matches DD, representing the 19th day of the month. T: The literal 'T' is correctly placed as the separator between the date and time. 10: Matches HH, representing the hour in 24-hour format. 30: Matches mm, representing the minutes past the hour. 00: Matches ss, representing the seconds. Z: Indicates that the time is in UTC.

skmainzmn commented 2 weeks ago

I have the same problem when trying to parse from format DD.MM.YYYY HH:mm