List of usage examples for java.util Calendar DATE
int DATE
To view the source code for java.util Calendar DATE.
Click Source Link
get
and set
indicating the day of the month. From source file:Main.java
public static long endOfThisMonth() { Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); cal.set(Calendar.MILLISECOND, 999); cal.add(Calendar.MONTH, 1);/*from w w w . j av a 2 s .c om*/ cal.add(Calendar.DATE, -1); Date date = cal.getTime(); return date.getTime(); }
From source file:Main.java
/** * the first day of month//from www. j av a 2s. c om * @param year * @param month * @return week position */ public static int getDayOfWeekInMonth(int year, int month) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.DATE, 1); return calendar.get(Calendar.DAY_OF_WEEK); }
From source file:Main.java
public static String formatSimpleDateStr(int year, int monthOfYear, int dayOfMonth) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, monthOfYear); cal.set(Calendar.DATE, dayOfMonth); return SIMPLE_DATE_FORMAT.format(cal.getTime()); }
From source file:Main.java
public static int getCurrentDate() { return calendar.get(Calendar.DATE); }
From source file:Main.java
public static String toDate(Date date, int add) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);// ww w .j a v a2s. c om calendar.add(Calendar.DATE, add); return toDate(calendar.getTime()); }
From source file:Main.java
/** * @param date//from w ww. ja va 2 s .c o m * @return */ public static String formatToYesterdayOrToday(Date date) { Calendar today = Calendar.getInstance(); Calendar yesterday = Calendar.getInstance(); yesterday.add(Calendar.DATE, -1); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); SimpleDateFormat timeFormatter = new SimpleDateFormat("HH:mm"); if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { return "Today, " + timeFormatter.format(date); } else if (calendar.get(Calendar.YEAR) == yesterday.get(Calendar.YEAR) && calendar.get(Calendar.DAY_OF_YEAR) == yesterday.get(Calendar.DAY_OF_YEAR)) { return "Yesterday, " + timeFormatter.format(date); } else { return DateFormat.format("MMM dd, ", date).toString() + timeFormatter.format(date); } }
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 int getDayCounts(Date startDate, Date endDate) { int days = 0; Calendar startCalendar = Calendar.getInstance(); startCalendar.setTime(startDate);/*from ww w. ja v a 2 s.c o m*/ Calendar endCalendar = Calendar.getInstance(); endCalendar.setTime(endDate); while (startCalendar.before(endCalendar)) { days++; startCalendar.add(Calendar.DATE, 1); } return days; }
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); 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:Main.java
/** * Add the given amount of days to the given calendar. The changes are reflected in the given * calendar./*from www . ja va 2 s . c o m*/ * @param calendar The calendar to add the given amount of days to. * @param days The amount of days to be added to the given calendar. Negative values are also * allowed, it will just go back in time. */ public static void addDays(Calendar calendar, int days) { calendar.add(Calendar.DATE, days); }