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:Main.java
public static Date parseDA(TimeZone tz, String s, boolean ceil) { Calendar cal = cal(tz);//from w w w . j a v a 2 s . co m int length = s.length(); if (!(length == 8 || length == 10 && !Character.isDigit(s.charAt(4)))) throw new IllegalArgumentException(s); try { int pos = 0; cal.set(Calendar.YEAR, Integer.parseInt(s.substring(pos, pos + 4))); pos += 4; if (!Character.isDigit(s.charAt(pos))) pos++; cal.set(Calendar.MONTH, Integer.parseInt(s.substring(pos, pos + 2)) - 1); pos += 2; if (!Character.isDigit(s.charAt(pos))) pos++; cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(s.substring(pos))); if (ceil) ceil(cal, Calendar.DAY_OF_MONTH); } catch (NumberFormatException e) { throw new IllegalArgumentException(s); } return cal.getTime(); }
From source file:cr.ac.siua.tec.utils.impl.CEInclusionPDFGenerator.java
/** * Fills the PDF file (inclusion.pdf) with the ticket values and returns base64 encoded string. *///from w w w. ja va2 s.c o m @Override public String generate(HashMap<String, String> formValues) { String originalPdf = PDFGenerator.RESOURCES_PATH + "inclusion.pdf"; try { PDDocument _pdfDocument = PDDocument.load(originalPdf); PDDocumentCatalog docCatalog = _pdfDocument.getDocumentCatalog(); PDAcroForm acroForm = docCatalog.getAcroForm(); formValues.remove("Queue"); formValues.remove("Justificacin"); //Set some fields manually. Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; if (month > 10 || month < 5) acroForm.getField("Semestre").setValue("I"); else acroForm.getField("Semestre").setValue("II"); if (month > 10 && acroForm.getField("Semestre").getValue().equals("I")) year++; acroForm.getField("Ao").setValue(String.valueOf(year)); //Fills enrolled courses table. String enrolledCourses[] = formValues.get("Cursos matriculados").split("\n"); for (int i = 0; i < enrolledCourses.length; i++) { String courseRow[] = enrolledCourses[i].split("-"); acroForm.getField("Cdigo" + Integer.toString(i)).setValue(courseRow[0]); acroForm.getField("Curso" + Integer.toString(i)).setValue(courseRow[1]); acroForm.getField("Grupo" + Integer.toString(i)).setValue(courseRow[2]); } formValues.remove("Cursos matriculados"); //Iterates through remaining custom fields. for (Map.Entry<String, String> entry : formValues.entrySet()) { acroForm.getField(entry.getKey()).setValue(entry.getValue()); } return encodePDF(_pdfDocument); } catch (IOException e) { e.printStackTrace(); System.out.println("Excepcin al llenar el PDF."); return null; } }
From source file:com.webbfontaine.valuewebb.model.validators.tt.TTDateValidator.java
@Override public boolean isValid(Object value) { int range = Utils.getAppCountry().equals(Constants.GH) ? -3 : -2; if (Utils.currentPage().contains("TtGenList")) { return true; }//from www . j a va2s .co m boolean notFuture; if (value != null && value instanceof Date) { Date dateValue = (Date) value; Calendar cal = Calendar.getInstance(); cal.add(Calendar.YEAR, range); notFuture = !DateUtils.truncate(dateValue, Calendar.DAY_OF_MONTH) .after(DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH)); // value must not be in future return notFuture && dateValue.after(cal.getTime()); } return true; }
From source file:com.aw.core.format.FechaEnTextoFormatter.java
public Object format(Object attributeValue) { Date date = (Date) attributeValue; Calendar cal = new GregorianCalendar(); cal.setTime(date);//w w w . j a va 2 s. c om int anio = cal.get(Calendar.YEAR); int mes = cal.get(Calendar.MONTH); int dia = cal.get(Calendar.DAY_OF_MONTH); Map meses = buildMesesMap(); String valor = dia + " de " + meses.get(mes) + " del " + anio; return valor; }
From source file:business.RequestNumberServiceTests.java
@Test public void incrementRequestNumber() { int year = Calendar.getInstance().get(Calendar.YEAR); RequestNumber n1 = requestNumberRepository.findByYear(year); if (n1 == null) { n1 = new RequestNumber(year); n1 = requestNumberRepository.save(n1); }/* w w w.j a va 2 s. c om*/ String n = requestNumberService.getNewRequestNumber(); assertNotEquals("Sequence number should be incremented.", n1.toString(), n); RequestNumber n2 = requestNumberRepository.findByYear(year); assertNotEquals("Sequence number should be incremented.", n1, n2); }
From source file:Main.java
public static Date getDateTimeFrom(Date time, Date date) { Date iTime, iDate;// www . ja v a 2 s.c o m Calendar calendar = Calendar.getInstance(); if (date == null) { iTime = time; iDate = new Date(); } else { iTime = time; iDate = date; } Calendar calendarDate = Calendar.getInstance(); calendarDate.setTime(iDate); Calendar calendarTime = Calendar.getInstance(); if (iTime != null) calendarTime.setTime(iTime); if (iTime != null) { calendar.set(Calendar.MINUTE, calendarTime.get(Calendar.MINUTE)); calendar.set(Calendar.HOUR_OF_DAY, calendarTime.get(Calendar.HOUR_OF_DAY)); } else { calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); } //calendar.set(Calendar.AM_PM, calendarTime.get(Calendar.AM_PM) ); calendar.set(Calendar.DAY_OF_MONTH, calendarDate.get(Calendar.DAY_OF_MONTH)); calendar.set(Calendar.MONTH, calendarDate.get(Calendar.MONTH)); calendar.set(Calendar.YEAR, calendarDate.get(Calendar.YEAR)); Date ret = calendar.getTime(); Log.v("!!!!!!!!!! calendar=", "" + ret); return ret; }
From source file:com.collabnet.ccf.core.utils.DateUtil.java
public static Date convertDateToTimeZone(Date date, String toTimeZone) { Calendar toCal = new GregorianCalendar(TimeZone.getTimeZone(toTimeZone)); Calendar fromCal = new GregorianCalendar(); fromCal.setTime(date);/*w w w . j a v a2s .c o m*/ toCal.set(fromCal.get(Calendar.YEAR), fromCal.get(Calendar.MONTH), fromCal.get(Calendar.DAY_OF_MONTH), fromCal.get(Calendar.HOUR_OF_DAY), fromCal.get(Calendar.MINUTE), fromCal.get(Calendar.SECOND)); toCal.set(Calendar.MILLISECOND, fromCal.get(Calendar.MILLISECOND)); return toCal.getTime(); }
From source file:Main.java
/** * Gets the default ARO trace folder name in the HH:MM:SS:DD:MM:YY format. * //from www .ja v a 2s . c o m * @return The default ARO trace folder name. */ public static String getDefaultTraceFolderName() { final Date systemDate = new Date(); final Calendar now = Calendar.getInstance(); final int currenthours = systemDate.getHours(); final int currentminutes = systemDate.getMinutes(); final int currentseconds = systemDate.getSeconds(); final int currentdate = now.get(Calendar.DATE); // java calendar int currentmonth = now.get(Calendar.MONTH); // As Jan is defined as 0 in currentmonth = currentmonth + 1; if (currentmonth >= 13) // As Jan is defined as 0 in java calendar currentmonth = 1; String currentMonth = Integer.toString(currentmonth); String currentDate = Integer.toString(currentdate); String currentHours = Integer.toString(currenthours); String currentMinutes = Integer.toString(currentminutes); String currentSeconds = Integer.toString(currentseconds - 1); if (currentmonth < 10) { currentMonth = ""; currentMonth = "0" + currentmonth; } if (currentdate < 10) { currentDate = ""; currentDate = "0" + currentdate; } if (currenthours < 10) { currentHours = ""; currentHours = "0" + currenthours; } if (currentminutes < 10) { currentMinutes = ""; currentMinutes = "0" + currentminutes; } if (currentseconds < 10) { currentSeconds = ""; currentSeconds = "0" + currentseconds; } final String folderName = now.get(Calendar.YEAR) + "-" + currentMonth + "-" + currentDate + "-" + currentHours + "-" + currentMinutes + "-" + currentSeconds; return folderName; }
From source file:ru.retbansk.utils.marshaller.Jaxb2MarshallerTest.java
@BeforeClass public static void beforeClass() { TaskReport taskReport = new TaskReport(); Date date = new Date(); Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); calendar.clear();/*from www. j a va 2 s . c om*/ calendar.set(Calendar.DATE, 1); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.YEAR, 1981); date = calendar.getTime(); taskReport.setDate(date); taskReport.setElapsedTime(4); taskReport.setStatus(STATUS); taskReport.setWorkDescription(WORK_DESCRIPTION); list = new ArrayList<TaskReport>(); list.add(taskReport); }
From source file:edu.wisc.my.stats.query.support.UWDataWareHouseInformationProvider.java
public UWDataWareHouseInformationProvider() { this.fieldMap.put(Calendar.YEAR, "DD.CALENDAR_YEAR_NUMBER"); this.fieldMap.put(Calendar.MONTH, "DD.CALENDAR_MONTH_NUMBER"); this.fieldMap.put(Calendar.DAY_OF_MONTH, "DD.CALENDAR_DAY_NUMBER"); }