Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-06-2002, 09:26 PM   PM User | #1
helpplease
New Coder

 
Join Date: Jul 2002
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
helpplease is an unknown quantity at this point
Time in military time?

How do I get the time in military time? Thanks for any help!
This is the code that I'm working with and I need it to be in military time:

<script LANGUAGE="JavaScript">
<!-- Begin
Stamp = new Date();
document.write('<span class="text">' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getYear() + '</span>&nbsp;');
var Hours;
var Mins;
var Secs;
var Time;
Hours = Stamp.getHours();
if (Hours >= 12) {
Time = " pm";
}
else {
Time = " am";
}
if (Hours > 12) {
Hours -= 12;
}
if (Hours == 0) {
Hours = 12;
}
Mins = Stamp.getMinutes();
if (Mins < 10) {
Mins = "0" + Mins;
}
Secs = Stamp.getSeconds();
if (Secs < 10) {
Secs = "0" + Secs;
}
document.write('<span class="text">' + Hours + ":" + Mins + ":" + Secs + Time + '</span>');// End -->
</script>

Thanks.
helpplease is offline   Reply With Quote
Old 08-06-2002, 09:34 PM   PM User | #2
kansel
Regular Coder

 
Join Date: Jul 2002
Location: Kansas, USA
Posts: 465
Thanks: 0
Thanked 45 Times in 44 Posts
kansel is on a distinguished road
Change this line

document.write('<span class="text">' + Hours + ":" + Mins + ":" + Secs + Time + '</span>');

to this

document.write('<span class="text">' + Stamp.getHours() + ":" + Mins + ":" + Secs + '</span>');
kansel is offline   Reply With Quote
Old 08-06-2002, 09:39 PM   PM User | #3
helpplease
New Coder

 
Join Date: Jul 2002
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
helpplease is an unknown quantity at this point
Thanks. Although, I feel like a moron now!!
helpplease is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:20 AM.


Advertisement
Log in to turn off these ads.