轉換:
從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.tkk7.com/zhyiwww
|----------------------------------------------------------------------------------------|
posted on 2014-02-19 18:20
zhyiwww 閱讀(807)
評論(0) 編輯 收藏 所屬分類:
j2ee