web-ui-pack
Version:
Web package with UI elements
22 lines (21 loc) • 1.15 kB
TypeScript
/** Returns parsed date from string based on pointed format
* @param format 'yyyy-MM-dd hh:mm:ss.fff AZ'
* @example
* "yyyy-MM-dd hh:mm:ss.fff Z" => "2022-04-23 16:09:12.234" // point 'Z' at the end for UTCdate
* "yyyy-MM-dd hh:mm:ss a" => "2022-04-23 04:09:12 pm" // point 'a' or 'A' at the end for 12hour format
* "yyyy-MM-dd hh:mm:ss.fff aZ" => "2022-04-23 04:09:12 pm" // point 'Z' at the end for UTCdate
* "yyyy-MM-dd hh:mm:ss" => "2022-04-23 16:09:12"
* "yyyy-M-d h:m:s" => "2022-4-23 13:9:12"
* "dd/MM/yyyy" => "23/04/2022"
* "yyyy-MM-ddThh:mm:ss.fffZ" // ISOstring
* "MMM d/yyyy, hh:mm A" => "Apr 23, 04:09 PM" (depends on localeInfo.namesMonthShort)
* "YYYYMMDD hhmmss" etc.
* @tutorial Troubleshooting
* * AM PM in the middle isn't supported (only at the end): use 'hh:mm, d/m/yyyy A' instead 'hh:mm A, d/m/yyyy'
*/
export default function dateFromString(v: string, format?: string, options?: {
/** Enables rule: if detected out of range value: day > 31 etc. then throws exception "Out of range";
* Disable it to return `null` instead
* @defaultValue true */
throwOutOfRange?: boolean;
}): Date | null;