时间转换

String转Date:

java.text.SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd "); String s= "2011-07-09 "; Date date = formatter.parse(s);
Date转String:

java.text.SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd ");
String date = formatter.format(new Date());//格式化数据

 

String---->Date:
public static void main(String[] args) throws Exception {
DateFormat fmt =new SimpleDateFormat("yyyy-MM-dd");
String s = "1987-10-10";
Date date = fmt.parse(s);
System.out.println(fmt.format(date));
}

public static void main(String[] args) {
String date="1987-10-10";
Date t = Date.valueOf(date);
System.out.println(t);
}

 

posted @ 2019-04-10 10:10  fatTmonkey  阅读(123)  评论(0编辑  收藏  举报