Java 字符串和时间互相转化 +时间戳

 一:字符串转换成date

String datatime="2015-09-22 15:16:48";
            SimpleDateFormat form = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");             
            Date date = form.parse(datatime);


二:date转换成String

SimpleDateFormat formatter  = new SimpleDateFormat("yyyy-MM-dd");
String strDate=formatter.format(new Date());

 

三:简单的时间戳

//时间戳通常是”yyyyMMddHHmmss“的,举例:
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String str = sdf.format(date);
//输出结果:20150704173752。
//备注:时间戳中的时间显示格式可以根据实际情况设置即可。

 

posted @ 2015-09-02 15:18  Smile_灰太狼  阅读(4320)  评论(0编辑  收藏  举报