posts - 1,  comments - 6,  trackbacks - 0
在JS中获取系统当前时间是用到Date这个对象,在实际应用时,常常会用到不同的显示格式,下面是一些处理方法!
  var now = new Date();
  strTime = now.toLocaleString();
  strYear = now.getYear();
  strMonth = now.getMonth();
  strDay = now.getDay();
   如果要将时间显示为2007/02/12这种格式,人们往往会采用如下的方式:
   displayTime = strYear +"/"+strMonth+"/"+strDay;
   也可以加入一些判断,以满足要求,但在实际中这种办法是做不到的,显示的格式与我们期望的要求,有很大的差别,为了可以满足要求我们做如下的处理,
   if(strTime.substring(5,6)<10){
 var displayTime = strTime.substring(0,4)+"/0"+strTime.substring(5,6)+"/"+strTime.substring(7,9);
 }else{
 var displayTime = strTime.substring(0,4)+"/"+strTime.substring(5,7)+"/"+strTime.substring(8,10);
 }
这样做虽然有些麻烦,但具有很强的灵活性。
posted @ 2007-02-12 14:21 Andy zhang 阅读(9161) | 评论 (6)编辑 收藏
仅列出标题  
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(1)

随笔档案

搜索

  •  

最新评论