标签:时间 nbsp format 需要 simple orm 字符串 str 使用
public static void main(String[] args) throws Exception {
/**
* 把时间对象转化成指定格式的字符串.
* 把指定格式的字符串转化成时间对象
* 一般使用
* */
SimpleDateFormat s1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
SimpleDateFormat s2 = new SimpleDateFormat("yyyy-MM-dd");
//将时间对象转化成字符串
System.out.println(s1.format(new Date()));
System.out.println(s2.format(new Date()));
//将符合指定格式的字符串转化成时间对象,字符串格式需要和指定格式一致
String time = "2016-10-22";
Date date = s2.parse(time);
System.out.println(date);
time = "2016-10-22 11:58:30";
date = s1.parse(time);
System.out.println(date);
}
标签:时间 nbsp format 需要 simple orm 字符串 str 使用
原文地址:http://www.cnblogs.com/hwgok/p/5987277.html