首页 > 其他 > 详细

Date、String、Calendar类型之间的转化

时间:2015-03-15 19:38:23      阅读:293      评论:0      收藏:0      [点我收藏+]

原文出处:http://fjfj910.iteye.com/blog/1202219

 

1.Calendar 转化 String
 //获取当前时间的具体情况,如年,月,日,week,date,分,秒等
        Calendar calendat = Calendar.getInstance();

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateStr = sdf.format(calendar.getTime());

 


2.String 转化Calendar

String str="2010-5-27";
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");

Date date =sdf.parse(str);

Calendar calendar = Calendar.getInstance();

calendar.setTime(date);

 

 

3.Date 转化String

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

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

 

 

 

4.String 转化Date
String str="2010-5-27";

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

Date birthday = sdf.parse(str);

 

 

5.Date 转化Calendar

Calendar calendar = Calendar.getInstance();
calendar.setTime(new java.util.Date());

 

6.Calendar转化Date

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

 

下面有个例子,插入oralce表类型为DATE的数据

 

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HHmmss");
    String date = sdf.format(new Date()); 

    -----------------------------------------

     String sql = "Insert into SM_SEND (*****************) " +
                  "values (*******************************

                   "‘,1," + "to_date(‘" +date+ "‘,‘YYYY-MM-DD HH24:MI:SS‘)" +
                   "," + "to_date(‘" +date+ "‘,‘YYYY-MM-DD HH24:MI:SS‘)" +
                   ",0,null,null,null,null,null,null,null)";

Date、String、Calendar类型之间的转化

原文:http://www.cnblogs.com/VinceYang1994/p/4340186.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!