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
public static int[] getTime(long time, String timeZone) { Calendar c = Calendar.getInstance(); if (timeZone != null && timeZone.length() != 0) { TimeZone tz = TimeZone.getTimeZone(timeZone); c = Calendar.getInstance(tz); }/* w w w. j ava2 s. c o m*/ c.setTimeInMillis(time); int y = c.get(Calendar.YEAR); int m = c.get(Calendar.MONTH); int d = c.get(Calendar.DAY_OF_MONTH); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); int second = c.get(Calendar.SECOND); return new int[] { y, m, d, hour, minute, second }; }
From source file:Main.java
private static final Calendar getUtcDate(int year, int month, int dayOfMonth) { final Calendar calendar = Calendar.getInstance(UTC_TIMEZONE, Locale.US); calendar.clear();/*from w ww . jav a 2s . com*/ calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); return calendar; }
From source file:Util.java
public static byte[] packDate(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date);/*from www.j a v a 2 s.c om*/ // Byte bits: 00000000 11111111 22222222 33333333 44444444 // Contents : 00YYYYYY YYYYYYMM MMDDDDDH HHHHMMMM MMSSSSSS byte[] bytes = new byte[5]; int s = c.get(Calendar.SECOND); int m = c.get(Calendar.MINUTE); int h = c.get(Calendar.HOUR_OF_DAY); int d = c.get(Calendar.DATE); int mm = c.get(Calendar.MONTH) + 1; int y = c.get(Calendar.YEAR); bytes[4] = (byte) ((m << 6) | s); bytes[3] = (byte) ((m >> 2) | (h << 4)); bytes[2] = (byte) ((h >> 4) | (d << 1) | (mm << 6)); bytes[1] = (byte) ((mm >> 2) | (y << 2)); bytes[0] = (byte) (y >> 6); return bytes; }
From source file:Main.java
/** * returns 1 if calendar1 > calendar2 0 if calendar1 = calendar2 (same month * and year) -1 if calendar1 > calendar2 * /* ww w . ja v a 2 s.c o m*/ * @param calendar1 * @param calendar2 */ public static byte compareMonth(Calendar calendar1, Calendar calendar2) { byte dayBefore = 0; int findDiff = calendar1.get(Calendar.YEAR) - calendar2.get(Calendar.YEAR); if (findDiff > 0) { dayBefore = 1; } else if (findDiff < 0) { dayBefore = -1; } else { findDiff = calendar1.get(Calendar.MONTH) - calendar2.get(Calendar.MONTH); if (findDiff > 0) { dayBefore = 1; } else if (findDiff < 0) { dayBefore = -1; } else { dayBefore = 0; } } return dayBefore; }
From source file:Main.java
public static int compareDates(java.util.Date startDate, java.util.Date endDate) { int interval = 0; calendarStartDate = Calendar.getInstance(); calendarStartDate.set(Calendar.YEAR, startDate.getYear()); calendarStartDate.set(Calendar.MONTH, startDate.getMonth()); calendarStartDate.set(Calendar.DAY_OF_MONTH, startDate.getDate()); calendarEndDate.set(Calendar.YEAR, endDate.getYear()); calendarEndDate.set(Calendar.MONTH, endDate.getMonth()); calendarEndDate.set(Calendar.DAY_OF_MONTH, endDate.getDate()); long diff = calendarEndDate.getTimeInMillis() - calendarStartDate.getTimeInMillis(); interval = (int) (diff / (24 * 60 * 60 * 1000) + 1); // plus one day return interval; }
From source file:Main.java
/** * Returns the month and release date of the movie * * @param releaseDate release date in yyyy-MM-dd format * @return month and year/*from ww w . j a va 2 s. c o m*/ */ @NonNull public static String getDisplayReleaseDate(String releaseDate) { if (TextUtils.isEmpty(releaseDate)) { return ""; } try { Calendar calendar = Calendar.getInstance(); calendar.setTime(DATE_FORMAT.parse(releaseDate)); return calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.ENGLISH) + " " + calendar.get(Calendar.YEAR); } catch (ParseException e) { return ""; } }
From source file:Main.java
/** * Decode a 16-bit encoded DOS date/time into a java date/time. * //w w w.j a v a2 s .com * @param dosDate * @param dosTime * @return long */ public static long decodeDateTime(int dosDate, int dosTime) { final Calendar cal = Calendar.getInstance(); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, (dosTime & 0x1f) * 2); cal.set(Calendar.MINUTE, (dosTime >> 5) & 0x3f); cal.set(Calendar.HOUR_OF_DAY, dosTime >> 11); cal.set(Calendar.DATE, dosDate & 0x1f); cal.set(Calendar.MONTH, ((dosDate >> 5) & 0x0f) - 1); cal.set(Calendar.YEAR, 1980 + (dosDate >> 9)); return cal.getTimeInMillis(); }
From source file:Main.java
public Main() { setSize(200, 100);/* ww w . j a v a 2 s . c om*/ setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(new FlowLayout(FlowLayout.LEFT, 4, 4)); add(new JLabel("Expiration Date:")); Date today = new Date(); JSpinner s = new JSpinner(new SpinnerDateModel(today, null, null, Calendar.MONTH)); JSpinner.DateEditor de = new JSpinner.DateEditor(s, "MM/yy"); s.setEditor(de); add(s); setVisible(true); }
From source file:DateUtils.java
public static String getDate() { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); return "" + year + "-" + month + "-" + day; }
From source file:DateUtils.java
/** * A method to get the current date as an array of components * 0 = year, 1 = month, 2 = day/* www . ja v a 2s .co m*/ * * @return an array of strings representing the current date */ public static String[] getCurrentDateAsArray() { GregorianCalendar calendar = new GregorianCalendar(); String[] fields = new String[3]; fields[0] = Integer.toString(calendar.get(Calendar.YEAR)); fields[1] = String.format("%02d", calendar.get(Calendar.MONTH) + 1); fields[2] = String.format("%02d", calendar.get(Calendar.DAY_OF_MONTH)); return fields; }