List of usage examples for java.text DateFormat getDateInstance
public static final DateFormat getDateInstance(int style, Locale aLocale)
From source file:DateValidator.java
/** * <p>Checks if the field is a valid date. The <code>Locale</code> is * used with <code>java.text.DateFormat</code>. The setLenient method * is set to <code>false</code> for all.</p> * * @param value The value validation is being performed on. * @param locale The locale to use for the date format, defaults to the default * system default if null.//from ww w . j av a 2 s .c o m * @return true if the date is valid. */ public boolean isValid(String value, Locale locale) { if (value == null) { return false; } DateFormat formatter = null; if (locale != null) { formatter = DateFormat.getDateInstance(DateFormat.SHORT, locale); } else { formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); } formatter.setLenient(false); try { formatter.parse(value); } catch (ParseException e) { return false; } return true; }
From source file:org.olat.core.util.Formatter.java
License:asdf
/** * formats the given date so it is friendly to read * /* ww w .j a va 2 s. c o m*/ * @param d the date * @return a String with the formatted date */ public String formatDate(Date d) { DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); df.setLenient(false); String da = df.format(d); return da; }
From source file:fr.paris.lutece.plugins.workflow.modules.rest.service.formatters.WorkflowFormatterXml.java
/** * Format the workflow//from ww w . j ava 2s .c o m * @param sbXml the XML * @param workflow the workflow */ private void formatWorkflow(StringBuffer sbXml, Workflow workflow) { DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, I18nService.getDefaultLocale()); String strDate = dateFormat.format(workflow.getCreationDate()); XmlUtil.beginElement(sbXml, WorkflowRestConstants.TAG_WORKFLOW); XmlUtil.addElement(sbXml, WorkflowRestConstants.TAG_ID_WORKFLOW, workflow.getId()); XmlUtil.addElement(sbXml, WorkflowRestConstants.TAG_NAME, workflow.getName()); XmlUtil.addElement(sbXml, WorkflowRestConstants.TAG_DESCRIPTION, workflow.getDescription()); XmlUtil.addElement(sbXml, WorkflowRestConstants.TAG_CREATION_DATE, strDate); XmlUtil.addElement(sbXml, WorkflowRestConstants.TAG_IS_ENABLE, Boolean.toString(workflow.isEnabled())); XmlUtil.addElement(sbXml, WorkflowRestConstants.TAG_WORKGROUP_KEY, workflow.getWorkgroup()); XmlUtil.endElement(sbXml, WorkflowRestConstants.TAG_WORKFLOW); }
From source file:com.sonicle.webtop.core.util.AppLocale.java
private SimpleDateFormat getDateFormatter(int style, Locale locale) { return (SimpleDateFormat) DateFormat.getDateInstance(style, locale); }
From source file:org.olat.core.util.StringHelper.java
/** * @param date/*from w ww .j av a2 s. c o m*/ * @param locale * @return formatted date */ public static String formatLocaleDateFull(long date, Locale locale) { if (date == -1) return "-"; return DateFormat.getDateInstance(DateFormat.FULL, locale).format(new Date(date)); }
From source file:dev.memento.MementoClient.java
/** * // ww w .j a v a 2s . c o m */ public MementoClient() { // Set the date and time format SimpleDateTime.mDateFormat = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.US); SimpleDateTime.mTimeFormat = DateFormat.getTimeInstance(DateFormat.DEFAULT, Locale.US); // Holds all the timemaps for the web page being viewed mTimeMaps = new HashSet<TimeMap>(); mMementos = new MementoList(); }
From source file:pl.exsio.ca.module.config.preachers.AssignmentsDataTable.java
@Override protected void doInit() { super.doInit(); if (this.preacher == null) { this.setEnabled(false); }//from ww w. j a v a2 s. co m this.setHeight("250px"); Converter dateConverter = new StringToDateConverter() { protected DateFormat getFormat(Locale locale) { return DateFormat.getDateInstance(DateFormat.MEDIUM, locale); } }; this.dataComponent.setConverter("date", dateConverter); }
From source file:action.OnlineBookingAction.java
@Actions({ @Action(value = "/mobile", results = { @Result(name = "success", location = "/WEB-INF/jsp/online/widget1.jsp"), @Result(name = "input", location = "/WEB-INF/jsp/online/validationError.jsp") }), @Action(value = "/goOnlineBookingCalendar", results = { @Result(name = "success", location = "/WEB-INF/jsp/online/widget1.jsp"), @Result(name = "input", location = "/WEB-INF/jsp/online/validationError.jsp") }) }) public String goOnlineBookingCalendar() { Booking booking = null;/*from ww w . jav a 2 s . co m*/ Structure structure = null; Locale locale = null; SimpleDateFormat sdf = null; String datePattern = null; locale = this.getLocale(); sdf = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale); datePattern = sdf.toPattern(); this.getSession().put("datePattern", datePattern); structure = this.getStructureService().findStructureById(this.getIdStructure()); this.setStructure(structure); booking = new Booking(); booking.setStatus("online"); booking.setId_structure(structure.getId()); this.getSession().put("onlineBooking", booking); this.getSession().put("structure", structure); this.setBooking(booking); return SUCCESS; }
From source file:pl.exsio.ca.module.config.groups.AssignmentsDataTable.java
@Override protected void doInit() { super.doInit(); if (this.group == null) { this.setEnabled(false); }/* w ww .j a v a2s . com*/ this.setHeight("250px"); Converter dateConverter = new StringToDateConverter() { @Override protected DateFormat getFormat(Locale locale) { return DateFormat.getDateInstance(DateFormat.MEDIUM, locale); } }; this.dataComponent.setConverter("date", dateConverter); }
From source file:pl.exsio.ca.module.terrain.evidence.AssignmentsDataTable.java
@Override protected void doInit() { super.doInit(); if (this.terrain == null) { this.setEnabled(false); }/*from w ww . j a v a2s . com*/ this.setHeight("250px"); Converter dateConverter = new StringToDateConverter() { @Override protected DateFormat getFormat(Locale locale) { return DateFormat.getDateInstance(DateFormat.MEDIUM, locale); } }; this.dataComponent.setConverter("startDate", dateConverter); this.dataComponent.setConverter("endDate", dateConverter); }