我搞错了,搞点代码吧: public static void main(String[] args) throws MalformedURLException, IOException { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); System.out.println(cal.get(Calendar.YEAR)); }
我搞错了,搞点代码吧: public static void main(String[] args) throws MalformedURLException, IOException { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); System.out.println(cal.get(Calendar.YEAR)); }
直接获取到java.sql.Date类型,然后在获取即可。
也不知道楼主用的是什么数据库,我下面就写个SQL Server的例子,其他的数据库都大同小异。select left(列名,4) from 表名
我有一个好主意哦建的表里其中有一个时间类型的字段 ,格式是xxxx年yy月zz日,但是我在java程序里只想用xxxx年这个数据,月和日不需要那就直接查询日期类型的数据啊,查询以后解析出年份就ok了[color=#CC99FF]Date date=获取的日期类型对象 SimpleDateFormat format = new SimpleDateFormat("yyyy"); String str = format.format(date); int year = Integer.parseInt(str); System.out.println("year=" + year);color]
刚设置颜色出了点问题,补充正确代码Date date=获取的日期类型对象 SimpleDateFormat format = new SimpleDateFormat("yyyy"); String str = format.format(date); int year = Integer.parseInt(str); System.out.println("year=" + year);
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
System.out.println(cal.get(Calendar.YEAR));
}
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
System.out.println(cal.get(Calendar.YEAR));
}
SimpleDateFormat format = new SimpleDateFormat("yyyy");
String str = format.format(date);
int year = Integer.parseInt(str);
System.out.println("year=" + year);color]
SimpleDateFormat format = new SimpleDateFormat("yyyy");
String str = format.format(date);
int year = Integer.parseInt(str);
System.out.println("year=" + year);
不要用JAVA写了