简体   繁体   中英

autoformat Time in TextBox ASP.Net Javascript

我需要使用Javascript在12或24小时格式中将时间格式化为10:00 PM或12:23 AM之类的时间

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>

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM