3

将格式化的字符串转换为日历的最简单和最简单的方法是什么?例如“dd.MM.yyyy”到日历?

4

3 回答 3

34
DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
Calendar cal  = Calendar.getInstance();
cal.setTime(df.parse(stringInstanceRepresentingDate));
于 2012-08-03T07:54:30.767 回答
1

试试这段代码:

String dateStr = "04/05/2010"; 

SimpleDateFormat curFormater = new SimpleDateFormat("dd/MM/yyyy"); 
Date dateObj = curFormater.parse(dateStr); 
Calendar calendar = Calendar.getInstance();
calendar .setTime(dateObj)
于 2012-08-03T07:55:45.023 回答
1

尝试:

SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
Calendar calendarDate = Calendar.getInstance();
if (calendarDate!= null) {
strdate = sdf.format(calendarDate.getTime());
}
于 2012-08-03T07:53:26.163 回答