Created
August 23, 2018 19:33
-
-
Save amanmeghrajani/c2e4c392de42031ba259503903e33a25 to your computer and use it in GitHub Desktop.
This file contains 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
// Formatted YYYYMMDDHHMMSS Int for timestamp calculation without needing any extra libs | |
const getFormattedDateTime = (dateObj) => { | |
let verifyDoubleDigits = (vals) => vals.map(val => val.length === 1 ? "0" + val : val) | |
let date = dateObj && dateObj.getMonth === 'function' ? datObj : new Date() | |
let year = date.getFullYear() .toString() | |
let month = (date.getMonth()+1).toString() | |
let day = date.getDate() .toString() | |
let hour = date.getHours() .toString() | |
let minutes = date.getMinutes() .toString() | |
let seconds = date.getSeconds() .toString() | |
let formatted = year | |
verifyDoubleDigits([month, day, hour, minutes, seconds]).forEach(val => formatted = formatted + val) | |
return parseInt(formatted) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment