Open vtplsp opened 8 months ago
You need to treat your "Z" token as an escape character (documented here). Example:
import dayjs from "dayjs";
import customParseFormat from "dayjs/plugin/customParseFormat.js";
dayjs.extend(customParseFormat);
const date = '2024-03-25T23:00:00.000Z';
const formats = [
"DD/MM/YYYY :) HHmmss",
"YYYY/MM/DD :) HHmmss.SSS",
"YYYY-MM-DDTHH:mm:ssZ",
"YYYY-MM-DDTHH:mm:ss.SSS[Z]", // Escape character
"YYYY-MM-DDTHH:mm:ss.SSS",
"YYYY-MM-DDTHH:mm:ss.SSS",
"DD MM YYYY HH:mm:ss Z",
"LLLL",
"LLL",
"llll",
"lll",
];
console.log(dayjs(date, formats, true).isValid()); // returns true
Describe the bug dayjs(value, formats, true).isValid() always returns false im using is with a post response to convert date to +1 gmt. if(dayjs(value, formats, true).isValid()) then convert code: import * as customParseFormat from 'dayjs/plugin/customParseFormat'; dayjs.extend(customParseFormat)
var formats = [ "DD/MM/YYYY :) HHmmss", "YYYY/MM/DD :) HHmmss.SSS", "YYYY-MM-DDTHH:mm:ssZ", "YYYY-MM-DDTHH:mm:ss.SSSZ", "YYYY-MM-DDTHH:mm:ss.SSS", "DD MM YYYY HH:mm:ss Z", "LLLL", "LLL", "llll", "lll", ];
dayjs('2024-03-25T23:00:00.000Z', formats, true).isValid()
the output will be false and I expect it to return true
Expected behavior A clear and concise description of what you expected to happen.
Information