Jump to content

Current time not formatting properly


sholladay

Recommended Posts

I realize this is rookie stuff, I don't have enough experience to string this together from them info on this site regarding this to make it work.

Can someone help me?

 

This shows current time, but if there's a 0 it drops it. So, for 3:03, it does 3:3.

 

I want it to show current date and time (not skipping 0's) - military time. Can anyone help?

 

jQuery(document).ready(function() {
var now = new Date();
jQuery("#RESULT_TextField-4").val(now.getHours()+":"+now.getMinutes());

 

Link to comment
Share on other sites

You have to format it dynamically if less than ten


function zerolessthan10(value)
{
if(parseInt(value) < 10)
{
return "0"+value;
}
else
{
return value;
}
}

$(document).ready(function() {
   var now = new Date();
var hours = zerolessthan10(now.getHours());
var mins = zerolessthan10(now.getMinutes());
   $("#RESULT_TextField-4").val(hours+":"+mins);
});

Edited by dsonesuk
  • Like 1
Link to comment
Share on other sites

You have to format it dynamically if less than ten


function zerolessthan10(value)
{
if(parseInt(value) < 10)
{
return "0"+value;
}
else
{
return value;
}
}

$(document).ready(function() {
   var now = new Date();
var hours = zerolessthan10(now.getHours());
var mins = zerolessthan10(now.getMinutes());
   $("#RESULT_TextField-4").val(hours+":"+mins);
});

Thank you! This worked.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...