List of usage examples for java.util Calendar WEEK_OF_YEAR
int WEEK_OF_YEAR
To view the source code for java.util Calendar WEEK_OF_YEAR.
Click Source Link
get
and set
indicating the week number within the current year. From source file:Main.java
public static int getWeek(Date date) { return getCalendar(date).get(Calendar.WEEK_OF_YEAR); }
From source file:Main.java
public static Date getLastWeekOfYear(Date date) { // Set time//from w w w.j a va 2s . c om Calendar calendar = Calendar.getInstance(); calendar.setTime(date); // Go to last week calendar.add(Calendar.WEEK_OF_YEAR, -1); return calendar.getTime(); }
From source file:Main.java
public static boolean isDatesInSameWeek(long lhsDate, long rhsDate) { Calendar lhsCalendar = getCalendarWithTime(lhsDate); int lhsWeek = lhsCalendar.get(Calendar.WEEK_OF_YEAR); int lhsYear = lhsCalendar.get(Calendar.YEAR); Calendar rhsCalendar = getCalendarWithTime(rhsDate); int rhsWeek = rhsCalendar.get(Calendar.WEEK_OF_YEAR); int rhsYear = rhsCalendar.get(Calendar.YEAR); return (lhsWeek == rhsWeek) && (lhsYear == rhsYear); }
From source file:Main.java
public static int getWeekFromDay(int year, int month, int day) { Calendar calendar = Calendar.getInstance(); calendar.clear();// www . j a va 2 s .c o m calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.DAY_OF_MONTH, day); return calendar.get(Calendar.WEEK_OF_YEAR); }
From source file:Main.java
public static int getWeekOfYear(String year, String month, String day) { Calendar cal = new GregorianCalendar(); cal.clear();//from ww w. jav a2s .c o m cal.set(new Integer(year).intValue(), new Integer(month).intValue() - 1, new Integer(day).intValue()); return cal.get(Calendar.WEEK_OF_YEAR); }
From source file:Main.java
public static int getWeekOfYear(Date date) { Calendar c = Calendar.getInstance(); c.setFirstDayOfWeek(Calendar.MONDAY); c.setTime(date);/*w ww . j a va 2 s. c om*/ int week = c.get(Calendar.WEEK_OF_YEAR) - 1; week = week == 0 ? 52 : week; return week > 0 ? week : 1; }
From source file:Main.java
public static String week() { // Create calendar instance Calendar calendar = Calendar.getInstance(); System.out.println("Current week of this month = " + calendar.get(Calendar.WEEK_OF_MONTH)); System.out.println("Current week of this year = " + calendar.get(Calendar.WEEK_OF_YEAR)); return ""; }
From source file:Main.java
/** * Get the displayable date from week and year * @param week week of year//from ww w . j a va2 s.co m * @param year year * @return Date string for displaying */ public static String getDate(int week, int year) { SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy"); Calendar cal = Calendar.getInstance(); // Log.i(TAG, sdf.format(cal.getTime())); cal.set(Calendar.YEAR, year); // Log.i(TAG, sdf.format(cal.getTime())); cal.set(Calendar.WEEK_OF_YEAR, week); // Log.i(TAG, sdf.format(cal.getTime())); cal.set(Calendar.DAY_OF_WEEK, 1); // Log.i(TAG, sdf.format(cal.getTime())); String start = sdf.format(cal.getTime()); cal.set(Calendar.DAY_OF_WEEK, 7); // Log.i(TAG, sdf.format(cal.getTime())); String end = sdf.format(cal.getTime()); return start + " to " + end; }
From source file:Main.java
public static int getWeekOfYear(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);/*from w w w . j a va 2 s . c om*/ return cal.get(Calendar.WEEK_OF_YEAR); }
From source file:Main.java
public static long getPeriodEnd(int periodType, long date) { final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(getPeriodStart(periodType, date)); switch (periodType) { case TYPE_DAY: { cal.add(Calendar.DAY_OF_YEAR, 1); break;/* w w w . j av a2s .c om*/ } case TYPE_WEEK: { cal.add(Calendar.WEEK_OF_YEAR, 1); break; } case TYPE_MONTH: { cal.add(Calendar.MONTH, 1); break; } case TYPE_YEAR: { cal.add(Calendar.YEAR, 1); break; } } cal.add(Calendar.MILLISECOND, -1); return cal.getTimeInMillis(); }