Last active
February 7, 2019 08:56
-
-
Save fhdalikhan/8f110b7a94c1335ddc5cd5496b45981a to your computer and use it in GitHub Desktop.
get unix timestamp from date, date format is YYYY-MM-DD
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
function getUnixTimeFromDate (date) { | |
if ( typeof(date) === 'undefined' ) { | |
throw 'Date is required'; | |
} | |
// using lodash _.isEmpty if available | |
if ( typeof window._.isEmpty === 'function' && _.isEmpty(date) ) { | |
throw 'Date cannot be empty.'; | |
} else if( date === '' || date == '' ) { | |
throw 'Date cannot be empty.'; | |
} | |
var dob = new Date(date).getTime() / 1000; | |
dob = parseInt(dob); | |
return dob; | |
} | |
// example | |
// console.log( getUnixTimeFromDate('2012-08-21') ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment