码迷,mamicode.com
首页 > 其他好文 > 详细

Calendar /String /Date 转换

时间:2016-06-25 15:05:06      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

Calendar 转化 String

Calendar calendat = Calendar.getInstance();

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

String dateStr = sdf.format(calendar.getTime());

 

String 转化Calendar

String str="2016-6-25";

SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");

Date date =sdf.parse(str);

Calendar calendar = Calendar.getInstance();

calendar.setTime(date); 

Date 转化String

SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");

String dateStr=sdf.format(new Date());

 

String 转化Date

String str="2016-6-25";

SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");

Date date= sdf.parse(str); 

 

Date 转化Calendar

Calendar calendar = Calendar.getInstance();

calendar.setTime(new java.util.Date());

 

Calendar转化Date

Calendar calendar = Calendar.getInstance();

java.util.Date date =calendar.getTime(); 

 

String 转成 Timestamp

Timestamp ts = Timestamp.valueOf("2016-6-25 15:11:00"); 

 

Date 转 TimeStamp

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String time = df.format(new Date());

Timestamp ts = Timestamp.valueOf(time);

 

Calendar /String /Date 转换

标签:

原文地址:http://www.cnblogs.com/daguoxiaoguo/p/5616334.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!