views:

580

answers:

2

I need to format time like 10:00 PM or 12:23 AM in both 12 or 24 hour format using Javascript

A: 

10 way to do it

http://www.webdevelopersnotes.com/tips/html/formatting_time_using_javascript.php3

<script type="text/javascript">
<!--

var a_p = "";
var d = new Date();

var curr_hour = d.getHours();

if (curr_hour < 12)
   {
   a_p = "AM";
   }
else
   {
   a_p = "PM";
   }
if (curr_hour == 0)
   {
   curr_hour = 12;
   }
if (curr_hour > 12)
   {
   curr_hour = curr_hour - 12;
   }

var curr_min = d.getMinutes();

document.write(curr_hour + " : " + curr_min + " " + a_p);

//-->
</script>
Haim Evgi
A: 

Here is some stuff from depressedpress.com. Hope this helps you!

Also, javascripttoolbox's date lib can also do few tricks with date-times.

TheVillageIdiot