zhyiwww
用平实的笔,记录编程路上的点点滴滴………
posts - 536,comments - 394,trackbacks - 0
 

 

转换:

从Date到String

DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

Date d = new Date();

String dstr = Df.format(d);

从String到日期

DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

Date d = df.parse("2014-02-19");

 

从date到calendar

Calendar cd1 = Calendar.getInstance();

Date sd1 = df.parse(startDate);        

cd1.setTime(sd1);

如:

startDate="2014-02-19";

从calender到Date

Calendar cd1 = Calendar.getInstance();

Date d = cd1.getTime();

 

 

格式化:

格式化Date

DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

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

格式化Calendar

DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

Calendar cd1 = Calendar.getInstance();

String dstr = df.format(cd1.getTime());

格式化日期字符串

DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

Date d = df.parse("2014-02-19");

DateFormat df1 = new SimpleDateFormat("MM-dd");

String dstr2 = df1.format(d);

 

 



|----------------------------------------------------------------------------------------|
                           版权声明  版权所有 @zhyiwww
            引用请注明来源 http://www.blogjava.net/zhyiwww   
|----------------------------------------------------------------------------------------|
posted on 2014-02-19 18:20 zhyiwww 阅读(769) 评论(0)  编辑  收藏 所属分类: j2ee

只有注册用户登录后才能发表评论。


网站导航: