Sotirios Delimanolis的應答是正確的。
FYI,這類日期時間工作很容易使用 joda庫。
下面是使用joda時間 2.3和 7的示例代碼。 我使用了巴黎時區和法國地區,但你可以用自己的。//© 2013 Basil Bourque. This source code may be used freely forever by anyone taking full responsibility for doing so.
//import org.joda.time.*;
//import org.joda.time.format.*;
//Specify time zone rather than rely on default.
DateTimeZone timeZone = DateTimeZone.forID("Europe/Paris" );
//Joda-Time offers many formatters, plus you may define your own.
//Using"forStyle" approach, pass first letter of the word Short/Medium/Long/Full, first for date and then for time.
DateTimeFormatter formatter = DateTimeFormat.forStyle("MM" ).withLocale( Locale.FRANCE ).withZone( timeZone );
DateTime now = new DateTime( timeZone );
for (int i &#61; 0; i <7; i&#43;&#43;){
DateTime dateTime &#61; now.plusDays( i );
//Extract descriptions.
String dayOfWeekAsText &#61; dateTime.dayOfWeek().getAsText( Locale.FRANCE );
String monthAsText &#61; dateTime.monthOfYear().getAsText( Locale.FRANCE );
String dateTimeAsText &#61; formatter.print( dateTime );
//Dump to console.
System.out.println("dayOfWeekAsText:" &#43; dayOfWeekAsText );
System.out.println("monthAsText:" &#43; monthAsText );
System.out.println("dateTimeAsText:" &#43; dateTimeAsText );
System.out.println();//Blank line.
}
運行時。dayOfWeekAsText: lundi
monthAsText: janvier
dateTimeAsText: 6 janv. 2014 18:35:18
dayOfWeekAsText: mardi
monthAsText: janvier
dateTimeAsText: 7 janv. 2014 18:35:18
dayOfWeekAsText: mercredi
monthAsText: janvier
dateTimeAsText: 8 janv. 2014 18:35:18
dayOfWeekAsText: jeudi
monthAsText: janvier
dateTimeAsText: 9 janv. 2014 18:35:18
dayOfWeekAsText: vendredi
monthAsText: janvier
dateTimeAsText: 10 janv. 2014 18:35:18
dayOfWeekAsText: samedi
monthAsText: janvier
dateTimeAsText: 11 janv. 2014 18:35:18
dayOfWeekAsText: dimanche
monthAsText: janvier
dateTimeAsText: 12 janv. 2014 18:35:18