List of usage examples for org.joda.time.format DateTimeFormatter print
public String print(ReadablePartial partial)
From source file:org.epics.archiverappliance.common.TimeUtils.java
public static String convertToHumanReadableString(long epochSeconds) { if (epochSeconds == 0) return "Never"; DateTimeFormatter fmt = DateTimeFormat.forPattern("MMM/dd/yyyy HH:mm:ss z"); DateTime dateTime = new DateTime(epochSeconds * 1000, DateTimeZone.getDefault()); String retval = fmt.print(dateTime); return retval; }
From source file:org.fao.geonet.kernel.harvest.harvester.thredds.Harvester.java
License:Open Source License
/** * Get uuid and change date for thredds dataset * * @param ds the dataset to be processed **///w w w . j a va 2 s .co m private RecordInfo getDatasetInfo(InvDataset ds) { Date lastModifiedDate = null; List<DateType> dates = ds.getDates(); for (DateType date : dates) { if (date.getType().equalsIgnoreCase("modified")) { lastModifiedDate = date.getDate(); } } String datasetChangeDate = null; if (lastModifiedDate != null) { DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); datasetChangeDate = fmt.print(new DateTime(lastModifiedDate)); } return new RecordInfo(getUuid(ds), datasetChangeDate); }
From source file:org.fcrepo.server.utilities.DateUtility.java
License:fedora commons license
/** * Converts an instance of java.util.Date into an ISO 8601 String * representation. Uses the date format yyyy-MM-ddTHH:mm:ss.SSSZ or * yyyy-MM-ddTHH:mm:ssZ, depending on whether millisecond precision is * desired./*from www .j a v a 2s . c o m*/ * * @param date * Instance of java.util.Date. * @param millis * Whether or not the return value should include milliseconds. * @return ISO 8601 String representation of the Date argument or null if * the Date argument is null. */ public static String convertDateToString(Date date, boolean millis) { if (date == null) { return null; } else { DateTimeFormatter df; if (millis) { // df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); df = FORMATTER_MILLISECONDS_T_Z; } else { // df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); df = FORMATTER_SECONDS_T_Z; } return df.print(date.getTime()); } }
From source file:org.fcrepo.server.utilities.DateUtility.java
License:fedora commons license
/** * Converts an instance of java.util.Date into a String using the date * format: yyyy-MM-ddZ./*from ww w.j a va 2 s. c om*/ * * @param date * Instance of java.util.Date. * @return Corresponding date string (returns null if Date argument is * null). */ public static String convertDateToDateString(Date date) { if (date == null) { return null; } else { // DateFormat df = new SimpleDateFormat("yyyy-MM-dd'Z'"); DateTimeFormatter df = FORMATTER_DATE_Z; return df.print(date.getTime()); } }
From source file:org.fcrepo.server.utilities.DateUtility.java
License:fedora commons license
/** * Converts an instance of java.util.Date into a String using the date * format: HH:mm:ss.SSSZ.//from w w w .j a v a2s. co m * * @param date * Instance of java.util.Date. * @return Corresponding time string (returns null if Date argument is * null). */ public static String convertDateToTimeString(Date date) { if (date == null) { return null; } else { // DateFormat df = new SimpleDateFormat("HH:mm:ss.SSS'Z'"); DateTimeFormatter df = FORMATTER_SECONDS_Z; return df.print(date.getTime()); } }
From source file:org.fenixedu.parking.domain.ParkingParty.java
License:Open Source License
public List<String> getOccupations() { List<String> occupations = new ArrayList<String>(); if (getParty().isPerson()) { Person person = (Person) getParty(); Teacher teacher = person.getTeacher(); if (teacher != null) { ExecutionSemester currentExecutionSemester = ExecutionSemester.readActualExecutionSemester(); String currentWorkingDepartmentName = teacher.getDepartment() != null ? teacher.getDepartment().getName() : null;/* w w w .j av a 2 s . c om*/ PersonContractSituation currentOrLastTeacherContractSituation = PersonContractSituation .getCurrentOrLastTeacherContractSituation(teacher); if (currentOrLastTeacherContractSituation != null) { String employeeType = RoleType.TEACHER.getLocalizedName(); if (ProfessionalCategory.isMonitor(teacher, currentExecutionSemester)) { employeeType = "Monitor"; } occupations.add(getOccupation(employeeType, teacher.getPerson().getEmployee().getEmployeeNumber().toString(), currentWorkingDepartmentName, currentOrLastTeacherContractSituation.getBeginDate(), currentOrLastTeacherContractSituation.getEndDate())); } String employeeType = "Docente Autorizado"; if (teacher.hasTeacherAuthorization()) { occupations .add(getOccupation(employeeType, teacher.getTeacherId(), currentWorkingDepartmentName, currentExecutionSemester.getBeginDateYearMonthDay().toLocalDate(), currentExecutionSemester.getEndDateYearMonthDay().toLocalDate())); } } PersonContractSituation currentEmployeeContractSituation = person.getEmployee() != null ? person.getEmployee().getCurrentEmployeeContractSituation() : null; if (currentEmployeeContractSituation != null) { Unit currentUnit = person.getEmployee().getCurrentWorkingPlace(); String thisOccupation = getOccupation(BundleUtil.getString(Bundle.ENUMERATION, "EMPLOYEE"), person.getEmployee().getEmployeeNumber().toString(), currentUnit == null ? null : currentUnit.getName(), currentEmployeeContractSituation.getBeginDate(), currentEmployeeContractSituation.getEndDate()); occupations.add(thisOccupation); } if (person.getEmployee() != null) { PersonContractSituation currentGrantOwnerContractSituation = person .getPersonProfessionalData() != null ? person.getPersonProfessionalData() .getCurrentPersonContractSituationByCategoryType(CategoryType.GRANT_OWNER) : null; if (currentGrantOwnerContractSituation != null) { Unit currentUnit = person.getEmployee().getCurrentWorkingPlace(); String thisOccupation = getOccupation(BundleUtil.getString(Bundle.ENUMERATION, "GRANT_OWNER"), person.getEmployee().getEmployeeNumber().toString(), currentUnit == null ? null : currentUnit.getName(), currentGrantOwnerContractSituation.getBeginDate(), currentGrantOwnerContractSituation.getEndDate()); occupations.add(thisOccupation); } } if (person.getResearcher() != null) { StringBuilder stringBuilder = new StringBuilder(BundleUtil.getString("resources.ParkingResources", "message.person.identification", new String[] { RoleType.RESEARCHER.getLocalizedName(), PartyClassification.getMostSignificantNumber(person).toString() })); String researchUnitNames = getWorkingResearchUnitNames(person); if (!StringUtils.isEmpty(researchUnitNames)) { stringBuilder.append(researchUnitNames).append("<br/>"); } PersonContractSituation currentResearcherContractSituation = person.getResearcher() != null ? person.getResearcher().getCurrentContractedResearcherContractSituation() : null; if (currentResearcherContractSituation != null) { Unit currentUnit = person.getEmployee() != null ? person.getEmployee().getCurrentWorkingPlace() : null; if (currentUnit != null) { stringBuilder.append(currentUnit.getName()).append("<br/>"); } DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy/MM/dd"); stringBuilder.append("(Data inicio: ") .append(fmt.print(currentResearcherContractSituation.getBeginDate())); if (currentResearcherContractSituation.getEndDate() != null) { stringBuilder.append(" - Data fim: ") .append(fmt.print(currentResearcherContractSituation.getEndDate())); } occupations.add(stringBuilder.append(")<br/>").toString()); } } Student student = person.getStudent(); if (student != null && RoleType.STUDENT.isMember(person.getUser())) { StringBuilder stringBuilder = null; for (Registration registration : student.getActiveRegistrations()) { StudentCurricularPlan scp = registration.getLastStudentCurricularPlan(); if (scp != null) { if (stringBuilder == null) { stringBuilder = new StringBuilder(BundleUtil.getString("resources.ParkingResources", "message.person.identification", new String[] { RoleType.STUDENT.getLocalizedName(), student.getNumber().toString() })); } stringBuilder.append("\n").append(scp.getDegreeCurricularPlan().getName()); stringBuilder.append("\n (").append(registration.getCurricularYear()).append(" ano"); if (isFirstTimeEnrolledInCurrentYear(registration)) { stringBuilder.append(" - 1 vez)"); } else { stringBuilder.append(")"); } stringBuilder.append("<br/>Media: ").append(registration.getAverage()); stringBuilder.append("<br/>"); } } if (stringBuilder != null) { occupations.add(stringBuilder.toString()); } for (PhdIndividualProgramProcess phdIndividualProgramProcess : person .getPhdIndividualProgramProcessesSet()) { if (phdIndividualProgramProcess.getActiveState().isPhdActive()) { String thisOccupation = getOccupation(RoleType.STUDENT.getLocalizedName(), student.getNumber().toString(), "\nPrograma Doutoral: " + phdIndividualProgramProcess.getPhdProgram().getName()); occupations.add(thisOccupation); } } } List<Invitation> invitations = Invitation.getActiveInvitations(person); if (!invitations.isEmpty()) { for (Invitation invitation : invitations) { String thisOccupation = getOccupation("Convidado", "-", invitation.getUnit().getName(), invitation.getBeginDate().toLocalDate(), invitation.getEndDate().toLocalDate()); occupations.add(thisOccupation); } } } return occupations; }
From source file:org.fenixedu.parking.domain.ParkingParty.java
License:Open Source License
private String getOccupation(String type, String identification, String workingPlace, LocalDate beginDate, LocalDate endDate) {//w w w.ja va2s .co m StringBuilder stringBuilder = new StringBuilder(getOccupation(type, identification, workingPlace)); if (beginDate != null) { DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy/MM/dd"); stringBuilder.append("(Data inicio: ").append(fmt.print(beginDate)); if (endDate != null) { stringBuilder.append(" - Data fim: ").append(fmt.print(endDate)); } } else { stringBuilder.append("(inactivo"); } stringBuilder.append(")<br/>"); return stringBuilder.toString(); }
From source file:org.finra.datagenerator.engine.scxml.tags.boundary.BoundaryDate.java
License:Apache License
/** * Takes a date, and retrieves the next business day * * @param dateString the date//from ww w. ja v a 2s . co m * @param onlyBusinessDays only business days * @return a string containing the next business day */ public String getNextDay(String dateString, boolean onlyBusinessDays) { DateTimeFormatter parser = ISODateTimeFormat.date(); DateTime date = parser.parseDateTime(dateString).plusDays(1); Calendar cal = Calendar.getInstance(); cal.setTime(date.toDate()); if (onlyBusinessDays) { if (cal.get(Calendar.DAY_OF_WEEK) == 1 || cal.get(Calendar.DAY_OF_WEEK) == 7 || isHoliday(date.toString().substring(0, 10))) { return getNextDay(date.toString().substring(0, 10), true); } else { return parser.print(date); } } else { return parser.print(date); } }
From source file:org.finra.datagenerator.engine.scxml.tags.boundary.BoundaryDate.java
License:Apache License
/** * Takes a date, and returns the previous business day * * @param dateString the date//w w w .ja v a 2 s .co m * @param onlyBusinessDays only business days * @return the previous business day */ public String getPreviousDay(String dateString, boolean onlyBusinessDays) { DateTimeFormatter parser = ISODateTimeFormat.date(); DateTime date = parser.parseDateTime(dateString).minusDays(1); Calendar cal = Calendar.getInstance(); cal.setTime(date.toDate()); if (onlyBusinessDays) { if (cal.get(Calendar.DAY_OF_WEEK) == 1 || cal.get(Calendar.DAY_OF_WEEK) == 7 || isHoliday(date.toString().substring(0, 10))) { return getPreviousDay(date.toString().substring(0, 10), true); } else { return parser.print(date); } } else { return parser.print(date); } }
From source file:org.finra.datagenerator.engine.scxml.tags.boundary.BoundaryDate.java
License:Apache License
/** * @param isNullable isNullable/*from ww w . j a v a 2 s. co m*/ * @param earliest lower boundary date * @param latest upper boundary date * @param onlyBusinessDays only business days * @return a list of boundary dates */ public List<String> positiveCase(boolean isNullable, String earliest, String latest, boolean onlyBusinessDays) { List<String> values = new LinkedList<>(); if (earliest.equalsIgnoreCase(latest)) { values.add(earliest); if (isNullable) { values.add(""); } return values; } DateTimeFormatter parser = ISODateTimeFormat.date(); DateTime earlyDate = parser.parseDateTime(earliest); DateTime lateDate = parser.parseDateTime(latest); String earlyDay = parser.print(earlyDate); String nextDay = getNextDay(earlyDate.toString().substring(0, 10), onlyBusinessDays); String prevDay = getPreviousDay(lateDate.toString().substring(0, 10), onlyBusinessDays); String lateDay = parser.print(lateDate); values.add(earlyDay); values.add(nextDay); values.add(prevDay); values.add(lateDay); if (isNullable) { values.add(""); } return values; }