下面列出了java.util.Calendar#getMinimalDaysInFirstWeek ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
static int getDays(String lang, String loc){
int errors=0;
Locale newlocale = new Locale(lang, loc);
Calendar newCal = Calendar.getInstance(newlocale);
int minDays = newCal.getMinimalDaysInFirstWeek();
System.out.println("The Min Days in First Week for "+ lang +"_" + loc + " is " + minDays);
if (minDays != 4){
System.out.println("Warning! Should be 4, not " + minDays +"!");
errors++;
}
return errors;
}
static int getDays(String lang, String loc){
int errors=0;
Locale newlocale = new Locale(lang, loc);
Calendar newCal = Calendar.getInstance(newlocale);
int minDays = newCal.getMinimalDaysInFirstWeek();
System.out.println("The Min Days in First Week for "+ lang +"_" + loc + " is " + minDays);
if (minDays != 4){
System.out.println("Warning! Should be 4, not " + minDays +"!");
errors++;
}
return errors;
}
static int getDays(String lang, String loc){
int errors=0;
Locale newlocale = new Locale(lang, loc);
Calendar newCal = Calendar.getInstance(newlocale);
int minDays = newCal.getMinimalDaysInFirstWeek();
System.out.println("The Min Days in First Week for "+ lang +"_" + loc + " is " + minDays);
if (minDays != 4){
System.out.println("Warning! Should be 4, not " + minDays +"!");
errors++;
}
return errors;
}
static int getDays(String lang, String loc){
int errors=0;
Locale newlocale = new Locale(lang, loc);
Calendar newCal = Calendar.getInstance(newlocale);
int minDays = newCal.getMinimalDaysInFirstWeek();
System.out.println("The Min Days in First Week for "+ lang +"_" + loc + " is " + minDays);
if (minDays != 4){
System.out.println("Warning! Should be 4, not " + minDays +"!");
errors++;
}
return errors;
}
static int getDays(String lang, String loc){
int errors=0;
Locale newlocale = new Locale(lang, loc);
Calendar newCal = Calendar.getInstance(newlocale);
int minDays = newCal.getMinimalDaysInFirstWeek();
System.out.println("The Min Days in First Week for "+ lang +"_" + loc + " is " + minDays);
if (minDays != 4){
System.out.println("Warning! Should be 4, not " + minDays +"!");
errors++;
}
return errors;
}
static int getDays(String lang, String loc){
int errors=0;
Locale newlocale = new Locale(lang, loc);
Calendar newCal = Calendar.getInstance(newlocale);
int minDays = newCal.getMinimalDaysInFirstWeek();
System.out.println("The Min Days in First Week for "+ lang +"_" + loc + " is " + minDays);
if (minDays != 4){
System.out.println("Warning! Should be 4, not " + minDays +"!");
errors++;
}
return errors;
}
static int getDays(String lang, String loc){
int errors=0;
Locale newlocale = new Locale(lang, loc);
Calendar newCal = Calendar.getInstance(newlocale);
int minDays = newCal.getMinimalDaysInFirstWeek();
System.out.println("The Min Days in First Week for "+ lang +"_" + loc + " is " + minDays);
if (minDays != 4){
System.out.println("Warning! Should be 4, not " + minDays +"!");
errors++;
}
return errors;
}
static int getDays(String lang, String loc){
int errors=0;
Locale newlocale = new Locale(lang, loc);
Calendar newCal = Calendar.getInstance(newlocale);
int minDays = newCal.getMinimalDaysInFirstWeek();
System.out.println("The Min Days in First Week for "+ lang +"_" + loc + " is " + minDays);
if (minDays != 4){
System.out.println("Warning! Should be 4, not " + minDays +"!");
errors++;
}
return errors;
}
static int getDays(String lang, String loc){
int errors=0;
Locale newlocale = new Locale(lang, loc);
Calendar newCal = Calendar.getInstance(newlocale);
int minDays = newCal.getMinimalDaysInFirstWeek();
System.out.println("The Min Days in First Week for "+ lang +"_" + loc + " is " + minDays);
if (minDays != 4){
System.out.println("Warning! Should be 4, not " + minDays +"!");
errors++;
}
return errors;
}
static int getDays(String lang, String loc){
int errors=0;
Locale newlocale = new Locale(lang, loc);
Calendar newCal = Calendar.getInstance(newlocale);
int minDays = newCal.getMinimalDaysInFirstWeek();
System.out.println("The Min Days in First Week for "+ lang +"_" + loc + " is " + minDays);
if (minDays != 4){
System.out.println("Warning! Should be 4, not " + minDays +"!");
errors++;
}
return errors;
}
static int getDays(String lang, String loc){
int errors=0;
Locale newlocale = new Locale(lang, loc);
Calendar newCal = Calendar.getInstance(newlocale);
int minDays = newCal.getMinimalDaysInFirstWeek();
System.out.println("The Min Days in First Week for "+ lang +"_" + loc + " is " + minDays);
if (minDays != 4){
System.out.println("Warning! Should be 4, not " + minDays +"!");
errors++;
}
return errors;
}
static int getDays(String lang, String loc){
int errors=0;
Locale newlocale = new Locale(lang, loc);
Calendar newCal = Calendar.getInstance(newlocale);
int minDays = newCal.getMinimalDaysInFirstWeek();
System.out.println("The Min Days in First Week for "+ lang +"_" + loc + " is " + minDays);
if (minDays != 4){
System.out.println("Warning! Should be 4, not " + minDays +"!");
errors++;
}
return errors;
}
static int getDays(String lang, String loc){
int errors=0;
Locale newlocale = new Locale(lang, loc);
Calendar newCal = Calendar.getInstance(newlocale);
int minDays = newCal.getMinimalDaysInFirstWeek();
System.out.println("The Min Days in First Week for "+ lang +"_" + loc + " is " + minDays);
if (minDays != 4){
System.out.println("Warning! Should be 4, not " + minDays +"!");
errors++;
}
return errors;
}
public static int getMysqlWeekMode(final Locale locale) {
/*
* From http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_week Mode First day of week Range Week 1 is the first week … 0 Sunday 0-53
* with a Sunday in this year 1 Monday 0-53 with more than 3 days this year 2 Sunday 1-53 with a Sunday in this year 3 Monday 1-53 with more than 3 days this year
* 4 Sunday 0-53 with more than 3 days this year 5 Monday 0-53 with a Monday in this year 6 Sunday 1-53 with more than 3 days this year 7 Monday 1-53 with a
* Monday in this year
*/
final Calendar c = Calendar.getInstance(locale);
final int firstDayOfWeek = c.getFirstDayOfWeek();
final int minimalDaysInFirstWeek = c.getMinimalDaysInFirstWeek();
if (firstDayOfWeek == Calendar.SUNDAY) {
// that could be mode 0,2,4,6
// Mode First day of week Range Week 1 is the first week …
// 0 Sunday 0-53 with a Sunday in this year
// 4 Sunday 0-53 with more than 3 days this year
// 2 Sunday 1-53 with a Sunday in this year
// 6 Sunday 1-53 with more than 3 days this year
if (minimalDaysInFirstWeek == 7) {
return 2;
} else if (minimalDaysInFirstWeek > 3) {
return 6;
} else {
return 4;
}
} else {
// otherwise it must be MONDAY
// that could be mode 1,3,5,7
// Mode First day of week Range Week 1 is the first week …
// 1 Monday 0-53 with more than 3 days this year
// 3 Monday 1-53 with more than 3 days this year
// 5 Monday 0-53 with a Monday in this year
// 7 Monday 1-53 with a Monday in this year
if (minimalDaysInFirstWeek == 7) {
return 7;
} else if (minimalDaysInFirstWeek > 3) {
return 3;
} else {
return 1;
}
}
}
public static int getMysqlWeekMode(final Locale locale) {
/*
* From http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_week Mode First day of week Range Week 1 is the first week … 0 Sunday 0-53
* with a Sunday in this year 1 Monday 0-53 with more than 3 days this year 2 Sunday 1-53 with a Sunday in this year 3 Monday 1-53 with more than 3 days this year
* 4 Sunday 0-53 with more than 3 days this year 5 Monday 0-53 with a Monday in this year 6 Sunday 1-53 with more than 3 days this year 7 Monday 1-53 with a
* Monday in this year
*/
final Calendar c = Calendar.getInstance(locale);
final int firstDayOfWeek = c.getFirstDayOfWeek();
final int minimalDaysInFirstWeek = c.getMinimalDaysInFirstWeek();
if (firstDayOfWeek == Calendar.SUNDAY) {
// that could be mode 0,2,4,6
// Mode First day of week Range Week 1 is the first week …
// 0 Sunday 0-53 with a Sunday in this year
// 4 Sunday 0-53 with more than 3 days this year
// 2 Sunday 1-53 with a Sunday in this year
// 6 Sunday 1-53 with more than 3 days this year
if (minimalDaysInFirstWeek == 7) {
return 2;
} else if (minimalDaysInFirstWeek > 3) {
return 6;
} else {
return 4;
}
} else {
// otherwise it must be MONDAY
// that could be mode 1,3,5,7
// Mode First day of week Range Week 1 is the first week …
// 1 Monday 0-53 with more than 3 days this year
// 3 Monday 1-53 with more than 3 days this year
// 5 Monday 0-53 with a Monday in this year
// 7 Monday 1-53 with a Monday in this year
if (minimalDaysInFirstWeek == 7) {
return 7;
} else if (minimalDaysInFirstWeek > 3) {
return 3;
} else {
return 1;
}
}
}