List of usage examples for java.util Calendar getFirstDayOfWeek
public int getFirstDayOfWeek()
SUNDAY
in the U.S., MONDAY
in France. From source file:DaysOfTheWeek.java
public static void main(String argv[]) { Locale usersLocale = Locale.getDefault(); DateFormatSymbols dfs = new DateFormatSymbols(usersLocale); String weekdays[] = dfs.getWeekdays(); Calendar cal = Calendar.getInstance(usersLocale); int firstDayOfWeek = cal.getFirstDayOfWeek(); int dayOfWeek; for (dayOfWeek = firstDayOfWeek; dayOfWeek < weekdays.length; dayOfWeek++) System.out.println(weekdays[dayOfWeek]); for (dayOfWeek = 0; dayOfWeek < firstDayOfWeek; dayOfWeek++) System.out.println(weekdays[dayOfWeek]); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // print current first day of the week int day = cal.getFirstDayOfWeek(); System.out.println("Current first day of the week:" + day); // set first day of the week as something else cal.setFirstDayOfWeek(Calendar.WEDNESDAY); // print altered first day of the week day = cal.getFirstDayOfWeek();//from w w w . j av a 2 s . co m ; System.out.println("Altered first day of the week:" + day); }
From source file:Main.java
public static void main(String[] args) { // create a new calendar Calendar cal = Calendar.getInstance(); // print the first day of the week System.out.println("First day is :" + cal.getFirstDayOfWeek()); int day = cal.getFirstDayOfWeek(); switch (day) { case (1)://w w w. java2s . co m System.out.println("Sunday"); break; case (2): System.out.println("Monday"); break; case 3: System.out.println("Tuesday"); break; case 4: System.out.println("Wednesday"); break; case 5: System.out.println("Thrusday"); break; case 6: System.out.println("Friday"); break; case 7: System.out.println("Saturday"); break; } }
From source file:Main.java
private static void setStartOfWeekToCalendar(Calendar c) { c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); setStartOfDayToCalendar(c);/* w w w . j a v a 2s.com*/ Log.d("La Cuenta: ", "Min of Current Week: " + DateFormat.getInstance().format(c.getTime())); }
From source file:Main.java
/** * * @param weekIndex/*from w w w . j av a2s. co m*/ * @param calendar * @return */ public static int getWeekIndex(int weekIndex, Calendar calendar) { int firstDayWeekPosition = calendar.getFirstDayOfWeek(); if (firstDayWeekPosition == 1) { return weekIndex; } else { if (weekIndex == 1) { return 7; } else { return weekIndex - 1; } } }
From source file:Main.java
public static Date startOfThisWeek() { Calendar cal = Calendar.getInstance(); int firstDay = cal.getFirstDayOfWeek(); cal.set(Calendar.DAY_OF_WEEK, firstDay); return startOfDay(cal.getTime()); }
From source file:com.ekom.ekomerp.global.DateTimeUtils.java
public static Date getFirstDayOfWeek(Date date, Locale locale) { Calendar calendar = getCalendarWithoutTime(date, locale); calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek()); return calendar.getTime(); }
From source file:Main.java
public static long getStartOfWeek(long week) { Calendar calendar = getCalendarWithTime(week); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.clear(Calendar.MINUTE); calendar.clear(Calendar.SECOND); calendar.clear(Calendar.MILLISECOND); // get start of this week in milliseconds calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek()); return calendar.getTimeInMillis(); }
From source file:Main.java
/** * @param period : today, this_week, this_month, this_year, none * @return a date filter string for making query. e.g. date >= 2013-1-1 for this_year * return null if period is none.// w w w .j a va2 s .c o m */ @SuppressWarnings("deprecation") public static String getDateFilterString(String period) { if (period == null) return null; Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH) + 1; // 1 - 12 int date = calendar.get(Calendar.DATE); // 1 - 31 String dateFilterString = null; if (period.equalsIgnoreCase("today")) { dateFilterString = "date >= " + year + "-" + month + "-" + date; } else if (period.contains("week")) { int offset = calendar.get(Calendar.DAY_OF_WEEK) - calendar.getFirstDayOfWeek(); long timeInMillis = calendar.getTimeInMillis() - offset * 24 * 60 * 60 * 1000; Date firstDay = new Date(timeInMillis); dateFilterString = "date >= " + (firstDay.getYear() + 1900) + "-" + firstDay.getMonth() + "-" + firstDay.getDate(); } else if (period.contains("month")) { dateFilterString = "date >= " + year + "-" + month + "-1"; } else if (period.contains("year")) { dateFilterString = "date >= " + year + "-1-1"; } return dateFilterString; }
From source file:Main.java
public static long getPeriodStart(int periodType, long date) { final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(date);//from w w w .j a v a 2 s . com switch (periodType) { case TYPE_DAY: { cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); break; } case TYPE_WEEK: { cal.setFirstDayOfWeek(Calendar.MONDAY); final int currentDayOfWeek = (cal.get(Calendar.DAY_OF_WEEK) + 7 - cal.getFirstDayOfWeek()) % 7; cal.add(Calendar.DAY_OF_YEAR, -currentDayOfWeek); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); break; } case TYPE_MONTH: { cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); break; } case TYPE_YEAR: { cal.set(Calendar.MONTH, 0); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); break; } } return cal.getTimeInMillis(); }