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:org.openmeetings.test.calendar.TestGetAppointment.java
@Test public void getAppoinment() { log.debug("getAppoinment enter"); Long userId = 1L;/*www .j a v a 2 s .c om*/ Calendar starttime = GregorianCalendar.getInstance(); starttime.set(Calendar.MONTH, starttime.get(Calendar.MONTH - 1)); Calendar endtime = GregorianCalendar.getInstance(); appointmentDao.getAppointmentsByRange(userId, starttime.getTime(), endtime.getTime()); assertTrue(true); }
From source file:de.hybris.platform.acceleratorservices.web.payment.validation.SopPaymentDetailsValidator.java
@Override public void validate(final Object object, final Errors errors) { final SopPaymentDetailsForm form = (SopPaymentDetailsForm) object; final Calendar startOfCurrentMonth = getCalendarResetTime(); startOfCurrentMonth.set(Calendar.DAY_OF_MONTH, 1); final Calendar startOfNextMonth = getCalendarResetTime(); startOfNextMonth.set(Calendar.DAY_OF_MONTH, 1); startOfNextMonth.add(Calendar.MONTH, 1); final Calendar start = parseDate(form.getCard_startMonth(), form.getCard_startYear()); final Calendar expiration = parseDate(form.getCard_expirationMonth(), form.getCard_expirationYear()); if (start != null && !start.before(startOfNextMonth)) { errors.rejectValue("card_startMonth", "payment.startDate.invalid"); }//from www. j av a 2 s. c om if (expiration != null && expiration.before(startOfCurrentMonth)) { errors.rejectValue("card_expirationMonth", "payment.startDate.invalid"); } if (start != null && expiration != null && start.after(expiration)) { errors.rejectValue("card_startMonth", "payment.startDate.invalid"); } if (StringUtils.isBlank(form.getBillTo_country())) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_country", "address.country.invalid"); } else { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_firstName", "address.firstName.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_lastName", "address.lastName.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_street1", "address.line1.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_city", "address.city.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_postalCode", "address.postcode.invalid"); } }
From source file:DateTimeUtil.java
/** Convert given date to string<br> * OutputFormat: yyyymmdd_hhmm/* w w w . j a v a 2 s . c om*/ * @return The Date/Time in the format: yyyymmdd_hhmm */ public static String convertToDateStamp(Calendar cal) { String year = String.valueOf(cal.get(Calendar.YEAR)); String month = String.valueOf(cal.get(Calendar.MONTH) + 1); if (month.length() == 1) { month = "0" + month; } String day = String.valueOf(cal.get(Calendar.DAY_OF_MONTH)); if (day.length() == 1) { day = "0" + day; } String hour = String.valueOf(cal.get(Calendar.HOUR_OF_DAY)); if (hour.length() == 1) { hour = "0" + hour; } String minute = String.valueOf(cal.get(Calendar.MINUTE)); if (minute.length() == 1) { minute = "0" + minute; } String second = String.valueOf(cal.get(Calendar.SECOND)); if (second.length() == 1) { second = "0" + second; } String dateStamp = year + month + day + "_" + hour + minute + second; return dateStamp; }
From source file:com.cemeterylistingswebtest.test.rest.LoginControllerTest.java
@Test(enabled = false) public void testCreate() { Long subID = new Long(17); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2008); calendar.set(Calendar.MONTH, Calendar.FEBRUARY); calendar.set(Calendar.DATE, 4); java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime()); UserRole user = new UserRole.Builder().setLevel(1).build(); Subscriber newSub = new Subscriber.Builder().setEmail("manfredOsulivan@horseRaddish.com") .setFirstName("Manfred").setSurname("Osulivan").setPwd("applesandsuch").setUsername("ManiFredOssy") .setSubscriptionDate(javaSqlDate).setUserRoleID(user).build(); HttpEntity<Subscriber> requestEntity = new HttpEntity<>(newSub, getContentType()); // Make the HTTP POST request, marshaling the request to JSON, and the response to a String ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/Subscriber/create", HttpMethod.POST, requestEntity, String.class); System.out.println(" THE RESPONSE BODY " + responseEntity.getBody()); System.out.println(" THE RESPONSE STATUS CODE " + responseEntity.getStatusCode()); System.out.println(" THE RESPONSE IS HEADERS " + responseEntity.getHeaders()); Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK); id = newSub.getSubscriberID();//from w ww .j a va2 s. co m }
From source file:ch.cyberduck.core.ftp.parser.vsFTPdEntryParserTest.java
@Test public void testParse() throws Exception { FTPFile parsed;//from www .j a v a2 s . co m // #5437 parsed = parser.parseFTPEntry("-rw-r--r-- 1 3642 3643 106 Nov 15 22:20 index.html"); assertNotNull(parsed); assertEquals("index.html", parsed.getName()); assertEquals(FTPFile.FILE_TYPE, parsed.getType()); assertEquals(106, parsed.getSize()); assertEquals(Calendar.NOVEMBER, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(15, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION)); }
From source file:MonthPanel.java
protected JPanel createDaysGUI() { JPanel dayPanel = new JPanel(true); dayPanel.setLayout(new GridLayout(0, dayNames.length)); Calendar today = Calendar.getInstance(); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.DAY_OF_MONTH, 1); Calendar iterator = (Calendar) calendar.clone(); iterator.add(Calendar.DAY_OF_MONTH, -(iterator.get(Calendar.DAY_OF_WEEK) - 1)); Calendar maximum = (Calendar) calendar.clone(); maximum.add(Calendar.MONTH, +1); for (int i = 0; i < dayNames.length; i++) { JPanel dPanel = new JPanel(true); dPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); JLabel dLabel = new JLabel(dayNames[i]); dPanel.add(dLabel);//w ww . jav a 2 s .co m dayPanel.add(dPanel); } int count = 0; int limit = dayNames.length * 6; while (iterator.getTimeInMillis() < maximum.getTimeInMillis()) { int lMonth = iterator.get(Calendar.MONTH); int lYear = iterator.get(Calendar.YEAR); JPanel dPanel = new JPanel(true); dPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); JLabel dayLabel = new JLabel(); if ((lMonth == month) && (lYear == year)) { int lDay = iterator.get(Calendar.DAY_OF_MONTH); dayLabel.setText(Integer.toString(lDay)); } dPanel.add(dayLabel); dayPanel.add(dPanel); iterator.add(Calendar.DAY_OF_YEAR, +1); count++; } for (int i = count; i < limit; i++) { JPanel dPanel = new JPanel(true); dPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); dPanel.add(new JLabel()); dayPanel.add(dPanel); } return dayPanel; }
From source file:Main.java
/** * Parse a date from ISO-8601 formatted string. It expects a format yyyy-MM-ddThh:mm:ss[.sss][Z|[+-]hh:mm] * * @param date ISO string to parse in the appropriate format. * @return the parsed date//from ww w . j a v a 2 s. c o m * @throws IllegalArgumentException if the date is not in the appropriate format */ public static Date parse(String date) { try { int offset = 0; // extract year int year = parseInt(date, offset, offset += 4); checkOffset(date, offset, '-'); // extract month int month = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, '-'); // extract day int day = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, 'T'); // extract hours, minutes, seconds and milliseconds int hour = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, ':'); int minutes = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, ':'); int seconds = parseInt(date, offset += 1, offset += 2); // milliseconds can be optional in the format int milliseconds = 0; // always use 0 otherwise returned date will include millis of current time if (date.charAt(offset) == '.') { checkOffset(date, offset, '.'); milliseconds = parseInt(date, offset += 1, offset += 3); } // extract timezone String timezoneId; char timezoneIndicator = date.charAt(offset); if (timezoneIndicator == '+' || timezoneIndicator == '-') { timezoneId = GMT_ID + date.substring(offset); } else if (timezoneIndicator == 'Z') { timezoneId = GMT_ID; } else { throw new IndexOutOfBoundsException("Invalid time zone indicator " + timezoneIndicator); } TimeZone timezone = TimeZone.getTimeZone(timezoneId); if (!timezone.getID().equals(timezoneId)) { throw new IndexOutOfBoundsException(); } Calendar calendar = new GregorianCalendar(timezone); calendar.setLenient(false); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minutes); calendar.set(Calendar.SECOND, seconds); calendar.set(Calendar.MILLISECOND, milliseconds); return calendar.getTime(); } catch (IndexOutOfBoundsException e) { throw new IllegalArgumentException("Failed to parse date " + date, e); } catch (NumberFormatException e) { throw new IllegalArgumentException("Failed to parse date " + date, e); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Failed to parse date " + date, e); } }
From source file:ch.cyberduck.core.ftp.parser.StingrayFTPEntryParserTest.java
/** * http://trac.cyberduck.ch/ticket/1198/*from w w w .j a v a2 s.c om*/ */ @Test public void testFile() { FTPFile parsed; parsed = parser.parseFTPEntry("-r--r--r-- 0 165100 165100 Aug 1 10:24 grau2.tif"); assertNotNull(parsed); assertEquals("grau2.tif", parsed.getName()); assertEquals(FTPFile.FILE_TYPE, parsed.getType()); assertEquals(Calendar.AUGUST, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(1, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); assertEquals(10, parsed.getTimestamp().get(Calendar.HOUR_OF_DAY)); assertEquals(24, parsed.getTimestamp().get(Calendar.MINUTE)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION)); }
From source file:ch.cyberduck.core.ftp.parser.OpensolarisFTPEntryParserTest.java
@Test public void testParse() throws Exception { FTPFile parsed;// www.ja va2 s. c om // #3689 parsed = parser.parseFTPEntry("drwxr-xr-x+ 5 niels staff 7 Sep 6 13:46 data"); assertNotNull(parsed); assertEquals(parsed.getName(), "data"); assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType()); assertEquals(7, parsed.getSize()); assertEquals(Calendar.SEPTEMBER, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(6, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION)); }
From source file:cn.mypandora.util.MyDateUtils.java
/** * ??/* ww w .j a va2 s. c om*/ * * @return */ public static String getMonthLastDay() { Calendar cal = Calendar.getInstance(); Calendar f = (Calendar) cal.clone(); f.clear(); // // f.set(Calendar.YEAR, cal.get(Calendar.YEAR)); // f.set(Calendar.MONTH, cal.get(Calendar.MONTH) + 1); // f.set(Calendar.MILLISECOND, -1); // return DateFormatUtils.format(f, DATE_FORMAT); // // f.set(Calendar.YEAR, cal.get(Calendar.YEAR)); // f.set(Calendar.MONTH, cal.get(Calendar.MONTH)); // f.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DATE)); // return DateFormatUtils.format(f, DATE_FORMAT); // (?) cal.set(Calendar.DATE, 1);// ?1? cal.add(Calendar.MONTH, 1);// ?1? cal.add(Calendar.DATE, -1);// ??? return DateFormatUtils.format(cal, DATE_FORMAT); }