1.Calendar 轉(zhuǎn)化 String
Calendar calendat = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateStr = sdf.format(calendar.getTime());
2.String 轉(zhuǎn)化Calendar
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 轉(zhuǎn)化String
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
String dateStr=sdf.format(new Date());
4.String 轉(zhuǎn)化Date
String str="2012-5-27";
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
Date date= sdf.parse(str);
5.Date 轉(zhuǎn)化Calendar
Calendar calendar = Calendar.getInstance();
calendar.setTime(newJava.util.Date());
6.Calendar轉(zhuǎn)化Date
Calendar calendar = Calendar.getInstance();
java.util.Date date =calendar.getTime();
7.String 轉(zhuǎn)成 Timestamp
Timestamp ts = Timestamp.valueOf("2012-1-14 08:11:00");
8.Date 轉(zhuǎn) TimeStamp
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = df.format(new Date());
Timestamp ts = Timestamp.valueOf(time);
Timestamp轉(zhuǎn)化為String:
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//定義格式,不顯示毫秒
Timestamp now = new Timestamp(System.currentTimeMillis());//獲取系統(tǒng)當前時間
String str = df.format(now);
String轉(zhuǎn)化為Timestamp:
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = df.format(new Date());
Timestamp ts = Timestamp.valueOf(time);