2009-08-30 48 views
3

SimpleDateFormat的 “W” 默认设置星期日是一周的第一天,例如:如何设置SimpleDateFormat“W”使用MONDAY是周的第一天?

SimpleDateFormat f = new SimpleDateFormat("W"); 
format.f(new Date()); 

我想成立 “W” 第一天是星期一,我尝试:

SimpleDateFormat f = new SimpleDateFormat("W"); 
Calendar c=Calendar.getInstance(); 
c.setTimeInMillis(input); 
c.setFirstDayOfWeek(Calendar.MONDAY); 
format.format(c.getTime()) 

,但没有效果。 plaese帮我, 谢谢!

回答

11

使用setCalendar()在你的SimpleDateFormat设置用于日期计算日历:

SimpleDateFormat format = new SimpleDateFormat("W"); 
Calendar calendar = Calendar.getInstance(); 
calendar.setFirstDayOfWeek(Calendar.MONDAY); 
format.setCalendar(calendar); 
format.format(whateverDateYouWantToFormat);` 
相关问题