将进行格式化的输出,也就是将时间格式转化为字符串格式
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String sdate = format.format(date);
将字符串格式时间转化为Date类型
String date1 = "2015-01-16";
Date date2 = null;
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
try {
date2 = format1.parse(date1);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.print(date2);
时间国际化方法转字符串输入,反之用parse可以字符串转时间
Date date = new Date(); DateFormat df = DateFormat.getDateInstance(DateFormat.FULL,Locale.JAPAN); String time = df.format(date); System.out.println(time);