List of usage examples for java.util Calendar YEAR
int YEAR
To view the source code for java.util Calendar YEAR.
Click Source Link
get
and set
indicating the year. From source file:com.sammyun.util.DateUtil.java
/** * ??_?yyyy-MM-dd// w w w . j a v a 2 s. co m * * @param year * @return String */ public static String getCurrYearFirstDay(int year) { SimpleDateFormat format = new SimpleDateFormat(default_format); Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.YEAR, year); Date currYearFirst = calendar.getTime(); return format.format(currYearFirst); }
From source file:org.sunzoft.sunstock.StockMain.java
protected void initData() throws Exception { dataSource = new StockDataSource(); dataSource.init();//from w w w . j ava2s . c o m dataSource.updateAccountData(); Calendar cld = Calendar.getInstance(); profits = dataSource.getDailyProfit(cld.get(Calendar.YEAR) + "0101", cld.get(Calendar.YEAR) + "1231"); }
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();/*w w w .ja v a2s . co m*/ }
From source file:com.tohours.imo.util.TohoursUtils.java
/** * ??n/* w w w. ja va2 s . c o m*/ * @param n * @return */ public static String getYearMonth(int n) { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MONTH, n); String yearMonth = calendar.get(Calendar.YEAR) + "" + formatNum(calendar.get(Calendar.MONTH) + 1) + ""; return yearMonth; }
From source file:net.ceos.project.poi.annotated.bean.ObjectNullBuilder.java
/** * Validate the ObjectNull based on the object build with the method * 'buildObjectNull'/*w w w.j a va2 s .co m*/ * * @param toValidate * the object to validate */ public static void validateObjectNull(ObjectNull toValidate) { ObjectNull base = buildObjectNull(); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Calendar calendarUnmarshal = Calendar.getInstance(); calendarUnmarshal.setTime(toValidate.getDateAttribute()); assertEquals(calendar.get(Calendar.YEAR), calendarUnmarshal.get(Calendar.YEAR)); assertEquals(calendar.get(Calendar.MONTH), calendarUnmarshal.get(Calendar.MONTH)); assertEquals(calendar.get(Calendar.DAY_OF_MONTH), calendarUnmarshal.get(Calendar.DAY_OF_MONTH)); assertEquals(base.getStringAttribute(), toValidate.getStringAttribute()); assertEquals(base.getIntegerAttribute(), toValidate.getIntegerAttribute()); assertEquals(base.getDoubleAttribute(), toValidate.getDoubleAttribute()); assertEquals(base.getLongAttribute(), toValidate.getLongAttribute()); assertEquals(base.getBooleanAttribute(), toValidate.getBooleanAttribute()); assertEquals(base.getJob().getJobCode(), toValidate.getJob().getJobCode()); assertEquals(base.getJob().getJobFamily(), toValidate.getJob().getJobFamily()); assertEquals(base.getJob().getJobName(), toValidate.getJob().getJobName()); assertEquals(base.getIntegerPrimitiveAttribute(), toValidate.getIntegerPrimitiveAttribute()); assertEquals(base.getDoublePrimitiveAttribute(), toValidate.getDoublePrimitiveAttribute()); assertEquals(base.getLongPrimitiveAttribute(), toValidate.getLongPrimitiveAttribute()); assertEquals(base.isBooleanPrimitiveAttribute(), toValidate.isBooleanPrimitiveAttribute()); assertEquals(base.getAddressInfo().getAddress(), toValidate.getAddressInfo().getAddress()); assertEquals(base.getAddressInfo().getNumber(), toValidate.getAddressInfo().getNumber()); assertEquals(base.getAddressInfo().getCity(), toValidate.getAddressInfo().getCity()); assertEquals(base.getAddressInfo().getCityCode(), toValidate.getAddressInfo().getCityCode()); assertEquals(base.getAddressInfo().getCountry(), toValidate.getAddressInfo().getCountry()); assertEquals(base.getFloatAttribute(), toValidate.getFloatAttribute()); assertEquals(base.getFloatPrimitiveAttribute(), toValidate.getFloatPrimitiveAttribute()); assertEquals(base.getUnitFamily(), toValidate.getUnitFamily()); assertEquals(base.getBigDecimalAttribute(), toValidate.getBigDecimalAttribute()); assertEquals(base.getShortAttribute(), toValidate.getShortAttribute()); assertEquals(base.getShortPrimitiveAttribute(), toValidate.getShortPrimitiveAttribute()); // TODO add new validation below }
From source file:com.epam.cme.storefront.forms.validation.PaymentDetailsValidator.java
@Override public void validate(final Object object, final Errors errors) { final PaymentDetailsForm form = (PaymentDetailsForm) object; if (StringUtils.isNotBlank(form.getStartMonth()) && StringUtils.isNotBlank(form.getStartYear()) && StringUtils.isNotBlank(form.getExpiryMonth()) && StringUtils.isNotBlank(form.getExpiryYear())) { final Calendar start = Calendar.getInstance(); start.set(Calendar.DAY_OF_MONTH, 0); start.set(Calendar.MONTH, Integer.parseInt(form.getStartMonth()) - 1); start.set(Calendar.YEAR, Integer.parseInt(form.getStartYear()) - 1); final Calendar expiration = Calendar.getInstance(); expiration.set(Calendar.DAY_OF_MONTH, 0); expiration.set(Calendar.MONTH, Integer.parseInt(form.getExpiryMonth()) - 1); expiration.set(Calendar.YEAR, Integer.parseInt(form.getExpiryYear()) - 1); if (start.after(expiration)) { errors.rejectValue("startMonth", "payment.startDate.invalid"); }//from w w w .j av a 2s . c om } final boolean editMode = StringUtils.isNotBlank(form.getPaymentId()); if (editMode || Boolean.TRUE.equals(form.getNewBillingAddress())) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.titleCode", "address.title.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.firstName", "address.firstName.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.lastName", "address.lastName.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.line1", "address.line1.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.townCity", "address.townCity.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.postcode", "address.postcode.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.countryIso", "address.country.invalid"); // ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.line2", // "address.line2.invalid"); // for some addresses this field is required by cybersource } }
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 w w w . j a va2 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:net.indialend.attendance.controller.HolidayController.java
@RequestMapping("/list") public ModelAndView holidayList(@RequestParam(defaultValue = "0", required = false) int year) { ModelAndView view = new ModelAndView("holiday/holidayList"); if (year == 0) { year = Calendar.getInstance().get(Calendar.YEAR); }/* ww w . ja va 2 s .com*/ view.addObject("holidayList", holidayService.getHoliday(year)); List<WorkingDays> workingDays = holidayService.getWorkingDays(); if (workingDays.isEmpty()) { for (WorkingDay workingDay : WorkingDay.values()) { WorkingDays wd = new WorkingDays(); wd.setWorkingDay(workingDay); workingDays.add(wd); } } view.addObject("workingdays", workingDays); return view; }
From source file:javaeetutorial.web.websocketbot.BotBean.java
public String respond(String msg) { String response = null;/*from w ww . j a v a 2 s . c om*/ String nbaresults; List<NBA> list = null; NBADecoder nbadecoder; /* Remove question marks */ msg = msg.toLowerCase().replaceAll("\\?", ""); if (msg.contains("how are you")) { response = "I'm doing great, thank you!"; } else if (msg.contains("how old are you")) { Calendar dukesBirthday = new GregorianCalendar(1995, Calendar.MAY, 23); Calendar now = GregorianCalendar.getInstance(); int dukesAge = now.get(Calendar.YEAR) - dukesBirthday.get(Calendar.YEAR); response = String.format("I'm %d years old.", dukesAge); } else if (msg.contains("when is your birthday")) { response = "My birthday is on May 23rd. Thanks for asking!"; } else if (msg.contains("") | msg.contains("?")) { String nbaUri = "http://op.juhe.cn/onebox/basketball/team?key=0564267c0eb0ed260583698c8ea0e605&dtype=json&team="; String divUri = "http://ltpapi.voicecloud.cn/analysis/?api_key=41g4M3f3b6C7L387G0c6XcEOcY5QwaMCWDRoYhGa&pattern=ws&&pattern=dp&format=plain&text="; String divresults = get(msg, divUri); String[] phrase = divresults.split("\\s"); for (int j = 0; j < phrase.length; j++) { nbaresults = get(phrase[j], nbaUri); nbadecoder = new NBADecoder(); list = nbadecoder.decode(nbaresults); if (list != null) { response += "?" + phrase[j]; for (NBA nba : list) { response += "\n" + nba.getPlaydate() + nba.getPlaytime() + ",?" + nba.getName1() + "VS" + "?" + nba.getName2() + "" + nba.getScore() + "" + nba.getLink(); response += "\n"; } } else { response = "???"; } } } else { response = "Sorry, I did not understand what you said. "; response += "You can ask me how I'm doing today; how old I am; or "; response += "what my favorite color is."; } try { Thread.sleep(1200); } catch (InterruptedException ex) { } return response; }
From source file:DateUtils.java
public static final String dateToString(Date dt, String dateformat) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(dt);/*w w w .ja v a2 s. c o m*/ StringBuffer ret = new StringBuffer(); String separator = new String(); if (dateformat.equals(DateUtils.FORMAT_YYYYMMDD)) { separator = "-"; } if (dateformat.equals(DateUtils.FORMAT_YYYYMMDD_SLASHES)) { separator = "/"; } ret.append(cal.get(Calendar.YEAR)); ret.append(separator); ret.append(cal.get(Calendar.MONTH) + 1); ret.append(separator); ret.append(cal.get(Calendar.DATE)); return ret.toString(); }