JS脚本里,如何将日期变量的格式改为字符,比如将2006-4-4改为"2006-04-04"?
我有一个日期型变量,要将他转换成一个固定格式的字符,比如将日期常量"2006-4-4"改
为固定格式字符"2006-04-04",如何实现?

解决方案 »

  1.   

    如果你是用STRUCTS
    你用<bean:wirte name="XXX" format="yyyy-MM-dd">    (MM---要大写)
    如果你真的要用JS,那么你自己先用slit("-")分割,再判断月和日是否大于10,如果大于就不变,小于就在前面+0就得啦!
      

  2.   

    试一下 java.text.SimpleDateFormat.java的类,怎么使用可以自己去看文档,这样提高比较快哦
      

  3.   

    kkdong(天爱飞猪) 
    回答很充分了。
      

  4.   

    function showtime () { 
    var now = new Date(); 
    var year = now.getYear();
    var month= now.getMonth()+1;
    if (month<10)
    month = "0" + month;
    var days = now.getDate();
    if (days<10)
       days = "0" +days;
    var hours = now.getHours(); 
    var minutes = now.getMinutes(); 
    var seconds = now.getSeconds() 
    var timeValue = "" + ((hours >12) ? hours -12 :hours) 
    timeValue += ((minutes < 10) ? ":0" : ":") + minutes 
    timeValue += ((seconds < 10) ? ":0" : ":") + seconds 
    timeValue += (hours >= 12) ? " P.M. " : " A.M. " 
    timeValue += "如果您是第一次访问本网站,请先看看在线帮助";
    window.status = year+"-"+month+"-"+days+" "+timeValue; 
    timerID = setTimeout("showtime()",1000); 
    timerRunning = true; 
    }