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:cz.cvut.kbss.wpa.service.test.PlayerServiceTest.java
@BeforeClass public static void setUp() { b = Calendar.getInstance();/*w w w . java2 s.c om*/ b.set(Calendar.YEAR, 1986); b.set(Calendar.MONTH, Calendar.APRIL); b.set(Calendar.DAY_OF_MONTH, 28); b.set(Calendar.HOUR, 0); b.set(Calendar.MINUTE, 0); b.set(Calendar.SECOND, 0); }
From source file:DateParser.java
private static Calendar getCalendar(String isodate) { // YYYY-MM-DDThh:mm:ss.sTZD StringTokenizer st = new StringTokenizer(isodate, "-T:.+Z", true); Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); calendar.clear();// www. j a va 2 s. c o m try { // Year if (st.hasMoreTokens()) { int year = Integer.parseInt(st.nextToken()); calendar.set(Calendar.YEAR, year); } else { return calendar; } // Month if (check(st, "-") && (st.hasMoreTokens())) { int month = Integer.parseInt(st.nextToken()) - 1; calendar.set(Calendar.MONTH, month); } else { return calendar; } // Day if (check(st, "-") && (st.hasMoreTokens())) { int day = Integer.parseInt(st.nextToken()); calendar.set(Calendar.DAY_OF_MONTH, day); } else { return calendar; } // Hour if (check(st, "T") && (st.hasMoreTokens())) { int hour = Integer.parseInt(st.nextToken()); calendar.set(Calendar.HOUR_OF_DAY, hour); } else { calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar; } // Minutes if (check(st, ":") && (st.hasMoreTokens())) { int minutes = Integer.parseInt(st.nextToken()); calendar.set(Calendar.MINUTE, minutes); } else { calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar; } // // Not mandatory now // // Secondes if (!st.hasMoreTokens()) { return calendar; } String tok = st.nextToken(); if (tok.equals(":")) { // secondes if (st.hasMoreTokens()) { int secondes = Integer.parseInt(st.nextToken()); calendar.set(Calendar.SECOND, secondes); if (!st.hasMoreTokens()) { return calendar; } // frac sec tok = st.nextToken(); if (tok.equals(".")) { // bug fixed, thx to Martin Bottcher String nt = st.nextToken(); while (nt.length() < 3) { nt += "0"; } nt = nt.substring(0, 3); // Cut trailing chars.. int millisec = Integer.parseInt(nt); // int millisec = Integer.parseInt(st.nextToken()) * 10; calendar.set(Calendar.MILLISECOND, millisec); if (!st.hasMoreTokens()) { return calendar; } tok = st.nextToken(); } else { calendar.set(Calendar.MILLISECOND, 0); } } else { throw new RuntimeException("No secondes specified"); } } else { calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); } // Timezone if (!tok.equals("Z")) { // UTC if (!(tok.equals("+") || tok.equals("-"))) { throw new RuntimeException("only Z, + or - allowed"); } boolean plus = tok.equals("+"); if (!st.hasMoreTokens()) { throw new RuntimeException("Missing hour field"); } int tzhour = Integer.parseInt(st.nextToken()); int tzmin = 0; if (check(st, ":") && (st.hasMoreTokens())) { tzmin = Integer.parseInt(st.nextToken()); } else { throw new RuntimeException("Missing minute field"); } if (plus) { calendar.add(Calendar.HOUR, -tzhour); calendar.add(Calendar.MINUTE, -tzmin); } else { calendar.add(Calendar.HOUR, tzhour); calendar.add(Calendar.MINUTE, tzmin); } } } catch (NumberFormatException ex) { throw new RuntimeException("[" + ex.getMessage() + "] is not an integer"); } return calendar; }
From source file:Main.java
public static Calendar createCalendar(int month, int dayOfMonth, int hour, int minute) { Calendar calendar = createCalendar(dayOfMonth, hour, minute); calendar.set(Calendar.MONTH, month); return calendar; }
From source file:name.martingeisse.common.util.Month.java
/** * @param c a {@link GregorianCalendar} that contains the month to return * @return the corresponding month// w ww . j a va 2s . c o m */ public static Month from(GregorianCalendar c) { return fromGregorianCalendarValue(c.get(Calendar.MONTH)); }
From source file:Main.java
/** * @param date//from ww w . j ava2 s . co m * @return */ public static String encodeTime(Date date) { StringBuilder result = new StringBuilder("T_"); Calendar cal = Calendar.getInstance(); cal.setTime(date); int month = cal.get(Calendar.MONTH) + 1; int year = cal.get(Calendar.YEAR); int day = cal.get(Calendar.DAY_OF_MONTH); int hour = cal.get(Calendar.HOUR_OF_DAY); int minute = cal.get(Calendar.MINUTE); int second = cal.get(Calendar.SECOND); //yyyy-MM-DD'T'kk:mm:ss result.append(year).append("-").append((month < 10) ? "0" : "").append(month).append("-") .append((day < 10) ? "0" : "").append(day).append("T").append((hour < 10) ? "0" : "").append(hour) .append(":").append((minute < 10) ? "0" : "").append(minute).append(":") .append((second < 10) ? "0" : "").append(second); return result.toString(); }
From source file:MonthSpinner.java
public MonthSpinner() { super("Month Spinner"); setSize(200, 100);// ww w. j a v a2 s.c om setDefaultCloseOperation(EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new FlowLayout(FlowLayout.LEFT, 4, 4)); c.add(new JLabel("Expiration Date:")); Date today = new Date(); // Start the spinner today, but don't set a min or max date // The increment should be a month JSpinner s = new JSpinner(new SpinnerDateModel(today, null, null, Calendar.MONTH)); JSpinner.DateEditor de = new JSpinner.DateEditor(s, "MM/yy"); s.setEditor(de); c.add(s); setVisible(true); }
From source file:com.worldline.easycukes.rest.utils.DateHelper.java
/** * Used to convert date value in json date format * * @param value// w w w . j ava2s. c om * @return */ public static String convertDateToJsonFormat(@NonNull final Date value) { log.info("setting the date value " + value + " to format json"); final Calendar calendar = Calendar.getInstance(); calendar.setTime(value); return calendar.get(Calendar.YEAR) + "-" + formatTo2Digit(calendar.get(Calendar.MONTH) + 1) + "-" + formatTo2Digit(calendar.get(Calendar.DAY_OF_MONTH)) + "T" + formatTo2Digit(calendar.get(Calendar.HOUR_OF_DAY)) + ":" + formatTo2Digit(calendar.get(Calendar.MINUTE)) + ":" + formatTo2Digit(calendar.get(Calendar.SECOND)) + ":" + calendar.get(Calendar.MILLISECOND) + "Z"; }
From source file:com.ykun.commons.utils.commons.DateUtils.java
/** * //from w w w .ja v a 2s .c o m * * @param date * @param monthAmount * @return Date */ public static Date addMonth(Date date, int monthAmount) { return addInteger(date, Calendar.MONTH, monthAmount); }
From source file:datojava.jcalendar.DJFechasEspInv.java
@Override public boolean isSpecial(Date date) { calendar.setTime(date);//from w ww . ja v a2 s . c om for (i = 0; i < djjcalendar.getFechasOcupadas().size(); i++) { if (calendar.get(Calendar.MONTH) == djjcalendar.getFechasOcupadas().get(i).get(Calendar.MONTH) && calendar.get(Calendar.DAY_OF_MONTH) == djjcalendar.getFechasOcupadas().get(i) .get(Calendar.DAY_OF_MONTH)) { return true; } } return false; }
From source file:egovframework.com.utl.wed.filter.DirectoryPathManager.java
/** * 2012/12/22//*from ww w. ja v a2s . c o m*/ * @param dateType * @return * @throws InvalidArgumentException */ public static String getDirectoryPathByDateType(DIR_DATE_TYPE policy) { Calendar calendar = Calendar.getInstance(); StringBuffer sb = new StringBuffer(); sb.append(calendar.get(Calendar.YEAR)).append(File.separator); if (policy.ordinal() <= DIR_DATE_TYPE.DATE_POLICY_YYYY_MM.ordinal()) { sb.append(StringUtils.leftPad(String.valueOf(calendar.get(Calendar.MONTH)), 2, '0')) .append(File.separator); } if (policy.ordinal() <= DIR_DATE_TYPE.DATE_POLICY_YYYY_MM_DD.ordinal()) { sb.append(StringUtils.leftPad(String.valueOf(calendar.get(Calendar.DATE)), 2, '0')) .append(File.separator); } return sb.toString(); }