Am looking to add a leading zero to Date minutes when under 10, while keeping it a number for querying
Followed the slice technique from javascript-add-leading-zeroes-to-date
This has yet to run for some reason:
var datetimeNow = new Date();
var minuteNow = datetimeNow.getMinutes();
// add a leading zero
if (minuteNow < 10 ) {
var ZeroMinuteNow = ('0' + datetimeNow.getMinutes()).slice(-2);
var minuteNow = parseInt(ZeroMinuteNow, 10);
console.log(minuteNow);
}
How about this:
var datetimeNow = new Date();
var minuteNow = datetimeNow.getMinutes();
// add a leading zero
if (minuteNow < 10 ) {
var muestra = ('0'+ minuteNow);
console.log(muestra);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.