下面的代码:运行时出现       现在时间:北京时间: 23:14:34 ??? 2011--4--13 
星期出现乱码这是为什么?
<%@ page contentType = "text/html;charset = GB2312"%>
<%@ page import = "java.util.Date,java.text.SimpleDateFormat"%>
<%   //格式化时间
Date date = new Date();
String dateFormatStr = "北京时间:\n\tH:mm:ss\n\tE \n\tyyyy--M--dd ";
SimpleDateFormat simpleFormat = new SimpleDateFormat(dateFormatStr);
out.println("<h3>现在时间:"+simpleFormat.format(date)+"</h3><br>");
%>

解决方案 »

  1.   

    现在时间:北京时间: 23:50:44 星期三 2011--4--13 这是我的运行结果,你再好好看看:<%@ page contentType="text/html;charset=GB2312"%>
    <%@ page import="java.util.Date,java.text.SimpleDateFormat"%>
    <%
    //格式化时间
    Date date = new Date();
    String dateFormatStr = "北京时间:\n\tH:mm:ss\n\tE \n\tyyyy--M--dd ";
    SimpleDateFormat simpleFormat = new SimpleDateFormat(dateFormatStr);
    out.println("<h3>现在时间:" + simpleFormat.format(date) + "</h3><br>");
    %>
      

  2.   

    跟过我精心的检查<%@ page contentType = "text/html;charset = GB2312"%>
    这一行指令的等号两旁多了空格是不能显示星期的  
      

  3.   

    解决了,怎么还不结贴了。最近项目中用到的
    //或得系统的当前时间
    var myDate = new Date(); 
    var year=myDate.getFullYear(); //获取完整的年份(4位,1970-????) 
    var month=myDate.getMonth()+1; //获取当前月份(0-11,0代表1月) 
    var day=myDate.getDate(); //获取当前日(1-31) 
    //var dates=year+"-"+month+"-"+day;
    var timeValue2 = year;
    timeValue2 += ((month < 10) ? "-0" : "-") + month+"";
    timeValue2 += ((day < 10) ? "-0" : "-") + day+"";