Why you dont use with Date Functions ?
let date: Date = new Date();
let fullDateAndTime: string = date.getFullYear() + "" + (date.getMonth()+1) + "" + date.getHours() + "" + date.getMinutes() + "" + date.getMilliseconds();
document.write(fullDateAndTime + ""); // Print YYYYMMDDHHMMSS
So you can check it with simple if (Month less then 10) :
let date: Date = new Date();
// date.getMonth() + 1 < 10 ? "0" + date.getMonth() + 1 : date.getMonth() + 1
// Check if the month is less than 10 with ternary if
let fullDateAndTime: string = date.getFullYear() + "" + (date.getMonth() + 1 < 10 ? "0" + date.getMonth() + 1 : date.getMonth() + 1) + "" + date.getHours() + "" + date.getMinutes() + "" + date.getMilliseconds();
document.write(fullDateAndTime + ""); // Print YYYYMMDDHHMMSS
It will print just as you wanted …
2
solved how to parse DD-MMM-YYYY to YYYYMMDDHHMMSS in javascript?