我这样得到了系统的时间,但是怎么得到单独的年份用于其他的计算呢?
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body>
<%=(new java.util.Date())%></body>
</html>

解决方案 »

  1.   

    Date d = new java.util.Date()
    Calendar c = Calendar.newInstance();
    c.setTime(d);
    int year = c.get(Calendar.YEAR) ;
      

  2.   

    修改后
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.util.*;" errorPage="" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head><body>
    <%=(new java.util.Date())%>
    <%
    Date d = new java.util.Date();
    Calendar c = Calendar.newInstance();
    c.setTime(d);
    int year = c.get(Calendar.YEAR) ;
    out.println(year);
    %>
    </body>
    </html>
    提示错误
    root cause org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 11 in the jsp file: /time.jsp
    Generated servlet error:
    The type Date is ambiguousAn error occurred at line: 11 in the jsp file: /time.jsp
    Generated servlet error:
    The method newInstance() is undefined for the type Calendar什么意思呢
      

  3.   

    Calendar.newInstance().get(Calendar.YEAR) ;
      

  4.   

    或者用那个格式化时间的class来处理, ***.format('Y',new Date());
      

  5.   

    Date d = new java.util.Date();改为
    java.util.Date d = new java.util.Date();
      

  6.   

    因为你导入了java.sql.* 和java.util.*两个包里都有Date类,但是实例化的时候没有指定明确的类型
      

  7.   

    SimpleDateFormat dtSimpleFormat=new SimpleDateFormat("yyyyMMddHHmmss");
      

  8.   

    修改后
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.util.*;" errorPage="" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head><body>
    <%=(new java.util.Date())%>
    <%
    java.util.Date d = new java.util.Date();
    Calendar c =Calendar.newInstance().get(Calendar.YEAR) ;
    c.setTime(d);
    int year = c.get(Calendar.YEAR) ;
    out.println(year);
    %>
    </body>
    </html>错误提示
    The method newInstance() is undefined for the type Calendar难道真的没定义
      

  9.   

    Calendar c =Calendar.newInstance().get(Calendar.YEAR) ;-》Calendar c =Calendar.newInstance()
      

  10.   

    但是现在提示问题在于newInstance()没定义啊
      

  11.   

    Calendar c =Calendar.getInstance() ;sorry ,呵呵
      

  12.   


    成了
    谢谢大家的帮助,非常感谢,尤其kevinliuu(@_@) 
    四个星要多长时间才有啊....