我要将日期类型2008-04-14 12:03:45,转换成日期类型 Date 2008,怎么转呢?
以下方法的结果是:Tue Jan 01 00:00:00 CST 2008,但是我这只想要2008,动态显示在页面上的,其他的不要啊,请各位大侠看看
logouttime是从数据库中查出来的日期类型的数据,格式是:2008-04-14 12:03:45,DateFormat df1 = new SimpleDateFormat("yyyy");
Date year = df1.parse(df1.format(logouttime));
以下方法的结果是:Tue Jan 01 00:00:00 CST 2008,但是我这只想要2008,动态显示在页面上的,其他的不要啊,请各位大侠看看
logouttime是从数据库中查出来的日期类型的数据,格式是:2008-04-14 12:03:45,DateFormat df1 = new SimpleDateFormat("yyyy");
Date year = df1.parse(df1.format(logouttime));
String strDate = "2008-04-14 12:03:45";
SimpleDateFormat format = new SimpleDateFormat("yyyy");
try{
System.out.println(format.format((format.parse(strDate))));
}catch(ParseException e){
e.printStackTrace();
}
如果是Date型直接format就行了
期望的结果也是日期类型的,不是字符串类型的
看来,好像真没办法