实例讲解String Date Calendar之间的转换
1.Calendar转化String
Calendarcalendat=Calendar.getInstance(); SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd"); StringdateStr=sdf.format(calendar.getTime());
2.String转化Calendar
Stringstr="2012-5-27"; SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd"); Datedate=sdf.parse(str); Calendarcalendar=Calendar.getInstance(); calendar.setTime(date);
3.Date转化String
SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd"); StringdateStr=sdf.format(newDate());
4.String转化Date
Stringstr="2012-5-27"; SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd"); Datedate=sdf.parse(str);
5.Date转化Calendar
Calendarcalendar=Calendar.getInstance(); calendar.setTime(newjava.util.Date());
6.Calendar转化Date
Calendarcalendar=Calendar.getInstance(); java.util.Datedate=calendar.getTime();
7.String转成Timestamp
Timestampts=Timestamp.valueOf("2012-1-1408:11:00");
8.Date转TimeStamp
SimpleDateFormatdf=newSimpleDateFormat("yyyy-MM-ddHH:mm:ss"); Stringtime=df.format(newDate()); Timestampts=Timestamp.valueOf(time);
以上这篇实例讲解StringDateCalendar之间的转换就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。