不新建实例,获取当前系统时间
new SimpleDateFormat("yyyyMMddHHmmss").format(System.currentTimeMillis());
//注:HH显示的是24小时制,hh显示的是12小时制
//获取毫秒时间戳
private static long getTimeMills(int year,int month,int day,int hour,int minute,int second) {
// TODO Auto-generated method stub
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(year,month,day,hour,minute,second);
Long timeMills = calendar.getTimeInMillis();
return timeMills;
}
//获取年月日时间戳
private static String getTime(long timeMills) {
// TODO Auto-generated method stub
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//12小时制
Date date = new Date();
date.setTime(timeMills);
String time = simpleDateFormat.format(date);
return time;
}