1.Date 轉(zhuǎn)化Calendar
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
2.Calendar轉(zhuǎn)化Date
Calendar calendar = Calendar.getInstance();
Date date =calendar.getTime();
3.Calendar 轉(zhuǎn)化 String
Calendar可獲取當(dāng)前時(shí)間的具體情況,如年细睡,月,日帝火,時(shí)溜徙,分,秒犀填,周蠢壹,月內(nèi)第幾天等。
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY,-1);//昨天
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String dateStr = sdf.format(calendar);
4.String 轉(zhuǎn)化Calendar
String str="2017-5-17";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date =sdf.parse(str);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
5.Date 轉(zhuǎn)化String
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
String dateStr=sdf.format(new Date());
6.String 轉(zhuǎn)化Date
String str="2017-5-17";
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse(str);
7.date轉(zhuǎn)化int
long nowTime = System.currentTimeMillis()/1000;
Integer nowTimeInt = new Long(nowTime).intValue();
8.int轉(zhuǎn)化date
long nowTimeLong=new Long(nowTimeInt).longValue()*1000;
DateFormat ymdhmsFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String nowTimeStr = ymdhmsFormat.format(nowTimeLong);