package com.jlc.box;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* 练习右下角弹框代替alert
* @author Administrator
*
*/
public class Showbox {
public static String getDateTimeYear(Date date) {
try {
java.util.Calendar c = java.util.Calendar.getInstance();
c.setTime(date);
return c.get(Calendar.YEAR) + "";
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
Date a = new Date();
String str = "2018年11月11日 ";
SimpleDateFormat format= new SimpleDateFormat("yyyy年MM月dd");
Date date;
try {
date = format.parse(str);
System.out.println(getDateTimeYear(date));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//str表示yyyy年MM月dd HH:mm:ss格式字符串
}
}