时间转字符串、字符串转时间(重中之重)---------------------------------------

时间转字符串--format(date):str
字符串转时间--parse(str):date

时间转字符串:
    Date date=new Date(); 
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
    String str=sdf.format(date); 
    System.out.println(str); 

字符串转时间:
    String str="2010-11-20 11:10:10";  
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
    Date date=sdf.parse(str);
    System.out.println(date); 
 

猜你喜欢

转载自blog.csdn.net/Richard_666/article/details/88298401