工具类之TimeUtils
/**
* 时间工具类
*/
public class TimeUtils {
public static String changeTimeMillisToDate(long timeMillis){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss ");
Date date = new Date(timeMillis);
String str = formatter.format(date);
return str;
}
public static String getCurrentTime() {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");
Date curDate = new Date(System.currentTimeMillis());//获取当前时间
String str = formatter.format(curDate);
return str;
}
public static String getCurrentTime2() {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss ");
Date curDate = new Date(System.currentTimeMillis());//获取当前时间
String str = formatter.format(curDate);
return str;
}
public static String getCurrentYearMonthDay() {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date curDate = new Date(System.currentTimeMillis());//获取当前时间
String str = formatter.format(curDate);
return str;
}
public static String getCurrentYear() {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月");
Date curDate = new Date(System.currentTimeMillis());//获取当前时间
String str = formatter.format(curDate);
return str;
}
public static String getYear() {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date curDate = new Date(System.currentTimeMillis());//获取当前时间
String str = formatter.format(curDate);
return str;
}
public static String getMonth() {
SimpleDateFormat formatter = new SimpleDateFormat("MM");
Date curDate = new Date(System.currentTimeMillis());//获取当前时间
String str = formatter.format(curDate);
return str;
}
}