Date转化为String:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
textDateTime.setText( sdf.format(new Date()) );
用Date获得星期数,0代表星期天,1代表星期一,......
int iWeek = new Date().getDay();
if( iWeek == 0 )
{
iWeek = 7;
}
Calendar获得星期数。1代表星期天,2代表星期一
int iNowWeek = calendar.get(Calendar.DAY_OF_WEEK);//0代表星期天
if(iNowWeek == 1)
{
iNowWeek = 7;
}
else
{
iNowWeek--;
}
三者之间的转化:
String装为Date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse(strDate2);
Date转为String
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String date = sdf.format(strDate2);
Date装为Calendar
Calendar aCalendar = Calendar.getInstance();
aCalendar.setTime(date)
Calendar装为Date
Date date = new Date( Calendar,getTime() )