简体   繁体   English

TextBox ASP.Net Javascript中的自动格式化时间

[英]autoformat Time in TextBox ASP.Net Javascript

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

10 way to do it 10种方法

http://www.webdevelopersnotes.com/tips/html/formatting_time_using_javascript.php3 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. 另外, javascripttoolbox的日期库还可以在日期时间上做一些技巧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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