标签:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time="2016-05-16 12:45:55";
Date date;
try {
date = format.parse(time);
System.out.print("Format To times:"+date);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = format.format(new Date());
System.out.println(time);
Date date=new Date();
Long time=date.getTime();
System.out.println(time);
Long time=1463390694218L;
Date date1 = new Date(time);
System.out.println(date1);
Calendar fromCalendar = Calendar.getInstance();
fromCalendar.setTime(new Date());
fromCalendar.add(Calendar.YEAR, 1);//加一年.
fromCalendar.add(Calendar.YEAR, -1);//减一年
fromCalendar.add(Calendar.MONTH, 1);//加一个月
fromCalendar.add(Calendar.MONTH, -1);//减一个月
fromCalendar.add(Calendar.DATE, 1);//加一天
fromCalendar.add(Calendar.DATE, -1);//减一天
fromCalendar.add(Calendar.HOUR, 1);//加一个小时
fromCalendar.add(Calendar.HOUR, 1);//减一个小时
fromCalendar.add(Calendar.MINUTE, 1);//加一分钟
fromCalendar.add(Calendar.MINUTE, -1);//减一分钟
long time = fromCalendar.getTime().getTime();//转为时间戳
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateStr = format.format(time);//转换为String
try {
Date date=format.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
标签:
原文地址:http://www.cnblogs.com/Seeasunnyday/p/5498888.html