Last active
August 14, 2020 13:34
-
-
Save surajp/d4b9522f979a851ed5cd6213088e9d31 to your computer and use it in GitHub Desktop.
Format JS date to ISO 8601 date time representation (YYYY-MM-DDThh:mm:ss.sTZD) in UTC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const formatToTwoDigits = (input)=>input?input.toString().padStart(2,'0'):null | |
const formatToDateTime = (inpDate) => inpDate && inpDate instanceof Date ? `${inpDate.getUTCFullYear()}-${formatToTwoDigits(inpDate.getUTCMonth()+1)}-${formatToTwoDigits(inpDate.getUTCDate())}T${formatToTwoDigits(inpDate.getUTCHours())}:${formatToTwoDigits(inpDate.getUTCMinutes())}:${formatToTwoDigits(inpDate.getUTCSeconds())}.${inpDate.getMilliseconds().toFixed(3)}Z`:null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment