Asked by tonelm54
at 2024-07-26 13:53:58
Point:500 Replies:7 POST_ID:829122USER_ID:10
Topic:
JavaScript;;jQuery
Is it possible to fill a variable with left 0s? For example 9 to make as 09?
I know in excel you can use text("00","09") which would return "09", or just "12" if you tried text("00","12").
Im trying to format current time, so Ive currently got:-
$('.clickToTime').click(function () {
var currentTime = new Date();
var month = currentTime.getMonth();
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
$(this).val(year + "/" + month + "/" + day + " " + hours + ":" + minutes + ":" + seconds);
});
Which works, but displays "2014/6/26 21:4:3" where I want it to display "2014/06/26 21:04:30".
Interesting enough, which I cannot figure out why is why it returns 6 instead of 7 for the month.... :-S
I know this is 2 questions, but hopefully someone is able to answer.
Thanks in advance
I know in excel you can use text("00","09") which would return "09", or just "12" if you tried text("00","12").
Im trying to format current time, so Ive currently got:-
$('.clickToTime').click(function () {
var currentTime = new Date();
var month = currentTime.getMonth();
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
$(this).val(year + "/" + month + "/" + day + " " + hours + ":" + minutes + ":" + seconds);
});
Which works, but displays "2014/6/26 21:4:3" where I want it to display "2014/06/26 21:04:30".
Interesting enough, which I cannot figure out why is why it returns 6 instead of 7 for the month.... :-S
I know this is 2 questions, but hopefully someone is able to answer.
Thanks in advance