时间类型和字符串类型之间的转换

时间类型和字符串类型之间的转换
 1 import org.junit.Test;
 2 
 3 import java.text.SimpleDateFormat;
 4 import java.util.Date;
 5 
 6 /**时间类型和字符串类型之间的转换
 7  * @author
 8  * @create
 9  **/
10 public class Test05 {
11 
12     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
13     SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
14 
15     @Test
16     public  void test(){
17         Date updateTime;
18         String string=sdfs.format(new Date());
19         try{
20             updateTime = sdfs.parse(sdfs.format(new Date()));
21         }catch(Exception e){
22             updateTime=null;
23         }
24         System.out.println(string);
25         System.out.println(updateTime);
26 
27     }
28 }

 

posted @ 2018-01-15 20:00  江南孤狼  阅读(906)  评论(0编辑  收藏  举报