1
2
3
4
5
|
Calendar calendat = Calendar.getInstance(); String dateStr = sdf.format(calendar.getTime()); |
2.String 转化Calendar
1
2
3
4
5
6
7
8
9
|
String str= "2012-5-27" ; SimpleDateFormat sdf= new SimpleDateFormat( "yyyy-MM-dd" ); Date date =sdf.parse(str); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); |
3.Date 转化String
1
2
3
|
SimpleDateFormat sdf= new SimpleDateFormat( "yyyy-MM-dd" ); String dateStr=sdf.format( new Date()); |
4.String 转化Date
1
2
3
4
5
|
String str= "2012-5-27" ; SimpleDateFormat sdf= new SimpleDateFormat( "yyyy-MM-dd" ); Date date= sdf.parse(str); |
5.Date 转化Calendar
1
2
3
|
Calendar calendar = Calendar.getInstance(); calendar.setTime( new java.util.Date()); |
6.Calendar转化Date
1
2
3
|
Calendar calendar = Calendar.getInstance(); java.util.Date date =calendar.getTime(); |
7.String 转成 Timestamp
1
|
Timestamp ts = Timestamp.valueOf( "2012-1-14 08:11:00" ); |
8.Date 转 TimeStamp
1
2
3
4
5
|
SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ); String time = df.format( new Date()); Timestamp ts = Timestamp.valueOf(time); |
以上这篇实例讲解String Date Calendar之间的转换就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。