Date object's default day
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 createDateString(day, month, year) { | |
return year + '-' + month + '-' + day; | |
} | |
function validateDate(dateStr) { | |
var ourDate = new Date(dateStr); | |
if(/(Invalid)/.test(ourDate)) { | |
return false; | |
} | |
return true; | |
} | |
var firstDate = createDateString('01', '01', '1990'); | |
console.log(validateDate(firstDate)); | |
var secondDate = createDateString('', '01', '1990'); | |
console.log(validateDate(secondDate)); | |
var thirdDate = createDateString(null, '01', '1990'); | |
console.log(validateDate(thirdDate)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://yournextcto.com/index.php/2016/09/30/date-objects-behaviour-when-using-yyyy-mm-dd-but-omitting-the-dd/