Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 change to 12 hour format

Author  Topic 

yvette
Yak Posting Veteran

74 Posts

Posted - 2010-10-19 : 04:41:14
Hi,
this is my html code.
it work, but show in 24hour format.
Can anyone help me change to 12hour format???

<html>
<head><title>ShowClock</title>
<script type="text/javascript">
function ShowTime()
{
var time=new Date()
var h=time.getHours()
var m=time.getMinutes()
var s=time.getSeconds()
// add a zero in front of numbers<10
m=checkTime(m)
s=checkTime(s)
document.getElementById('txt').value=h+" : "+m+" : "+s
t=setTimeout('ShowTime()',1000)
}
function checkTime(i)
{
if (i<10)
{
i="0" + i
}
return i
}
</script>
</head>
<body bgcolor="#ccccff">
<input type="button" value="Show Clock!" onClick="ShowTime()">
<font color="olive">
(Please click on this button)
</font><br /><br />
<input type="text" id="txt">
</body>
</html>


Thanks...

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-19 : 05:05:49
[code]function getClockTime()
{
var now = new Date();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
var ap = "AM";
if (hour > 11) { ap = "PM"; }
if (hour > 12) { hour = hour - 12; }
if (hour == 0) { hour = 12; }
if (hour < 10) { hour = "0" + hour; }
if (minute < 10) { minute = "0" + minute; }
if (second < 10) { second = "0" + second; }
var timeString = hour +
':' +
minute +
':' +
second +
" " +
ap;
return timeString;
} // function getClockTime()

[/code]
Source: http://www.web-source.net/web_development/javascript_date.htm


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

yvette
Yak Posting Veteran

74 Posts

Posted - 2010-10-19 : 11:56:12
thanks for reply...
but i try the code below, its not work...
can anyone show me the way???
thankss...

<html>
<head><title>ShowClock</title>
<script type="text/javascript">
function getClockTime()
{
var now = new Date();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
var ap = "AM";
if (hour > 11) { ap = "PM"; }
if (hour > 12) { hour = hour - 12; }
if (hour == 0) { hour = 12; }
if (hour < 10) { hour = "0" + hour; }
if (minute < 10) { minute = "0" + minute; }
if (second < 10) { second = "0" + second; }
var timeString = hour +
':' +
minute +
':' +
second +
" " +
ap;
return timeString;
} // function getClockTime()
</script>
</head>
<body bgcolor="#ccccff">
<input type="button" value="Show Clock!" onClick="getClockTime()">
<font color="olive">
(Please click on this button)
</font><br /><br />
<input type="text" id="txt">
</body>
</html>
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-19 : 12:05:06
onClick="document.getElementById('txt').value=getClockTime()"
instead of
onClick="getClockTime()"




No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

yvette
Yak Posting Veteran

74 Posts

Posted - 2010-10-21 : 03:26:08
Thanks...
that what i want...
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-21 : 03:27:06
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -