List of usage examples for java.util Calendar MONTH
int MONTH
To view the source code for java.util Calendar MONTH.
Click Source Link
get
and set
indicating the month. From source file:Main.java
@SuppressLint("DefaultLocale") public static void SaveLastWallpaperDate(Context context, Calendar dateTime) { int year = dateTime.get(Calendar.YEAR); int month = dateTime.get(Calendar.MONTH); int date = dateTime.get(Calendar.DATE); String dateTimeToString = String.format("%d/%d/%d", year, month, date); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); preferences.edit().putString("wallpaper_date", dateTimeToString).commit(); }
From source file:Main.java
public static boolean CoversFYStart(Calendar one, Calendar two, Calendar fy_start) throws Exception { if (one == null || two == null) throw new Exception("CoversFYStart: Null dates passed in"); if (fy_start == null) throw new Exception("CoversFYStart: Null FY Start"); int fy_month = fy_start.get(Calendar.MONTH); int fy_day = fy_start.get(Calendar.DAY_OF_MONTH); Calendar cal = (Calendar) one.clone(); while (true) { cal.add(Calendar.DATE, 1); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); if (month == fy_month && day == fy_day) break; }/*from www .ja v a2 s .c o m*/ return cal.before(two); }
From source file:Util.java
public static int getMonthFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from w w w. ja v a 2 s .com*/ return calendar.get(Calendar.MONTH); }
From source file:Main.java
public static boolean checkToday(String date) { Calendar today = Calendar.getInstance(); Calendar day = StringToCalendar(date); return ((today.get(Calendar.YEAR) == day.get(Calendar.YEAR)) && (today.get(Calendar.MONTH) == day.get(Calendar.MONTH)) && (today.get(Calendar.DAY_OF_MONTH) == day.get(Calendar.DAY_OF_MONTH))); }
From source file:Main.java
public static Calendar GetLastMonthLeftRange(Calendar today) { Calendar calendar = (Calendar) today.clone(); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.add(Calendar.MONTH, -1); calendar.add(Calendar.MINUTE, 0); return calendar; }
From source file:Main.java
/** * Returns a date formatted in ANSI SQL. * * @param date the Date./*from w w w. java2 s. c om*/ * @return a date String. */ public static String getSqlDateString(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); String yearString = String.valueOf(year); String monthString = month < 10 ? "0" + month : String.valueOf(month); String dayString = day < 10 ? "0" + day : String.valueOf(day); return yearString + "-" + monthString + "-" + dayString; }
From source file:MainClass.java
public static Timestamp makeTimestamp(int year, int month, int day, int hour, int minute, int second, int millisecond) { Calendar cal = new GregorianCalendar(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month - 1); cal.set(Calendar.DATE, day);//from w ww . ja va2s . co m cal.set(Calendar.HOUR_OF_DAY, hour); cal.set(Calendar.MINUTE, minute); cal.set(Calendar.SECOND, second); cal.set(Calendar.MILLISECOND, millisecond); // now convert GregorianCalendar object to Timestamp object return new Timestamp(cal.getTimeInMillis()); }
From source file:Util.java
public static Date getSunday(Date today) { Calendar cal = Calendar.getInstance(); cal.setTime(today);/* w w w .j av a 2s. co m*/ int dow = cal.get(Calendar.DAY_OF_WEEK); while (dow != Calendar.SUNDAY) { int date = cal.get(Calendar.DATE); int month = cal.get(Calendar.MONTH); int year = cal.get(Calendar.YEAR); if (date == getMonthLastDate(month, year)) { if (month == Calendar.DECEMBER) { month = Calendar.JANUARY; cal.set(Calendar.YEAR, year + 1); } else { month++; } cal.set(Calendar.MONTH, month); date = 1; } else { date++; } cal.set(Calendar.DATE, date); dow = cal.get(Calendar.DAY_OF_WEEK); } return cal.getTime(); }
From source file:Main.java
public static boolean isSixMonthsAgo(Calendar c1, Calendar c2) { int year1 = c1.get(Calendar.YEAR); int month1 = c1.get(Calendar.MONTH); int year2 = c2.get(Calendar.YEAR); int month2 = c2.get(Calendar.MONTH); if ((year1 * 12 + month1) - (year2 * 12 + month2) > 6) return true; return false; }
From source file:Main.java
public static Date getDateTimeFrom(int hour, int minute) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_MONTH, 0); calendar.set(Calendar.MONTH, 0); calendar.set(Calendar.YEAR, 0); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); Date ret = calendar.getTime(); return ret;/*from www .j av a 2 s .co m*/ }