Example usage for java.text DateFormat getDateInstance

List of usage examples for java.text DateFormat getDateInstance

Introduction

In this page you can find the example usage for java.text DateFormat getDateInstance.

Prototype

public static final DateFormat getDateInstance(int style, Locale aLocale) 

Source Link

Document

Gets the date formatter with the given formatting style for the given locale.

Usage

From source file:org.olat.commons.calendar.ui.components.FullCalendarComponentRenderer.java

@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator,
        RenderResult renderResult, String[] args) {

    FullCalendarComponent fcC = (FullCalendarComponent) source;
    FullCalendarElement fcE = fcC.getCalendarElement();
    Form rootForm = fcE.getRootForm();//from  w  ww.  j  av a2s .  c om
    String id = "o_c" + fcC.getDispatchID();
    String formId = fcE.getFormDispatchId();
    String printId = "fc_p" + fcC.getDispatchID();

    Calendar cal = Calendar.getInstance(fcC.getTranslator().getLocale());
    int firstDay = cal.getFirstDayOfWeek() - 1;
    cal = Calendar.getInstance();
    cal.setTime(fcC.getCurrentDate());

    Calendar calRef = Calendar.getInstance(fcC.getTranslator().getLocale());
    calRef.set(Calendar.DATE, 25);
    calRef.set(Calendar.MONTH, 11);
    calRef.set(Calendar.YEAR, 2013);

    String formatted = DateFormat.getDateInstance(DateFormat.SHORT, fcC.getTranslator().getLocale())
            .format(calRef.getTime());
    boolean firstMonth = (formatted.indexOf("12") < formatted.indexOf("25"));

    String amFormatted = DateFormat.getTimeInstance(DateFormat.SHORT, fcC.getTranslator().getLocale())
            .format(calRef.getTime());
    boolean ampm = amFormatted.contains("AM") || amFormatted.contains("PM");

    sb.append("<script type='text/javascript'>\n").append("/* <![CDATA[ */ \n").append("jQuery(function() {\n")
            .append("   jQuery('#").append(id).append("').fullCalendar( {\n").append("   header: {\n")
            .append("     left: 'prev,print,next today',\n").append("     center: 'title',\n")
            .append("     right: 'month,agendaWeek,agendaDay'\n").append("   },\n").append("   buttonText: {\n")
            .append("     today: '").append(escapeJavaScript(translator.translate("cal.thisweek")))
            .append("',\n").append("     month: '").append(escapeJavaScript(translator.translate("cal.month")))
            .append("',\n").append("     day: '").append(escapeJavaScript(translator.translate("cal.day")))
            .append("',\n").append("     week: '").append(escapeJavaScript(translator.translate("cal.week")))
            .append("',\n").append("     print: '").append(escapeJavaScript(translator.translate("print")))
            .append("'\n").append("   },\n").append("   monthNames: ").append(getMonthLong(translator))
            .append(",\n").append("   monthNamesShort: ").append(getMonthShort(translator)).append(",\n")
            .append("   dayNames: ").append(getDayLong(translator)).append(",\n").append("   dayNamesShort: ")
            .append(getDayShort(translator)).append(",\n").append("   allDayText:'")
            .append(translator.translate("cal.form.allday")).append("',\n").append("   axisFormat:'")
            .append(ampm ? "h(:mm)tt" : "H.mm").append("',\n").append("   timeFormat:'")
            .append(ampm ? "h(:mm)tt" : "H.mm").append("',\n").append("   titleFormat: {\n")
            .append("     month: 'MMMM yyyy',\n").append("     week: ")
            .append(firstMonth ? "\"MMM d[ yyyy]{ '&#8212;'[ MMM] d yyyy}\""
                    : "\"d. [ MMM] [ yyyy]{ '&#8212;' d. MMM yyyy}\"")
            .append(",\n").append("     day: ")
            .append(firstMonth ? "'dddd, MMM d, yyyy'" : "'dddd, d. MMM yyyy'").append("\n").append("   },\n")
            .append("   columnFormat: {\n").append("     month: 'ddd',\n").append("     week: ")
            .append(firstMonth ? "'ddd M/d'" : "'ddd d.M.'").append(",\n").append("     day: ")
            .append(firstMonth ? "'dddd M/d'" : "'dddd d.M.'").append("\n").append("   },\n").append("   year:")
            .append(cal.get(Calendar.YEAR)).append(",\n").append("   month:").append(cal.get(Calendar.MONTH))
            .append(",\n").append("   date:").append(cal.get(Calendar.DAY_OF_MONTH)).append(",\n")
            .append("   firstDay:").append(firstDay).append(",\n").append("   defaultView:'")
            .append(fcC.getViewName()).append("',\n").append("   weekNumbers: true,\n")
            .append("   editable: true,\n").append("   selectable: true,\n").append("   selectHelper: true,\n")
            .append("     eventSources:[");
    int count = 0;
    for (KalendarRenderWrapper calWrapper : fcC.getKalendarRenderWrappers()) {
        if (calWrapper.getKalendarConfig().isVis()) {
            String calId = calWrapper.getKalendar().getCalendarID();
            String color = calWrapper.getKalendarConfig().getCss();
            if (StringHelper.containsNonWhitespace(color) && color.startsWith("o_cal_")) {
                color = color.substring(6, color.length());
            }
            if (count++ != 0)
                sb.append(",");
            sb.append("{\n").append("   url:'").append(fcC.getMapperUrl()).append("/").append(calId)
                    .append(".json',\n").append("   color:'").append(color).append("'\n").append("}");
        }
    }
    sb.append("   ],\n").append("   eventAfterRender: function(event, element, view) {\n")
            .append("     element.each(function(index, el) {\n")
            .append("       jQuery(el).attr('id', 'o_cev_' + view.name + '_' + event.id);\n")
            .append("     });\n").append("   },\n").append("   viewDisplay: function(view) {\n")
            .append(FormJSHelper.generateXHRFnCallVariables(rootForm, formId, 1))
            .append("     o_ffXHREvent(formNam, dispIdField, dispId, eventIdField, eventInt,'evChangeView',view.name,'start',view.start.getTime());\n")
            .append("   },\n")
            .append("     eventDrop: function(calEvent, dayDelta, minuteDelta, allDay, revertFunc, jsEvent, ui, view) {\n")
            .append(FormJSHelper.generateXHRFnCallVariables(rootForm, formId, 1))
            .append("     o_ffXHREvent(formNam, dispIdField, dispId, eventIdField, eventInt,'evMove',calEvent.id,'dayDelta',dayDelta,'minuteDelta',minuteDelta,'allDay',allDay);\n")
            .append("     },\n").append("   select: function(startDate, endDate, allDay, jsEvent, view) {\n")
            .append(FormJSHelper.generateXHRFnCallVariables(rootForm, formId, 1))
            .append("     o_ffXHREvent(formNam, dispIdField, dispId, eventIdField, eventInt,'evAdd','new','start',startDate.getTime(),'end',endDate.getTime(),'allDay',allDay);\n")
            .append("   },\n").append("   eventClick: function(calEvent, jsEvent, view) {\n")
            .append(FormJSHelper.generateXHRFnCallVariables(rootForm, formId, 1))
            .append("     o_ffXHREvent(formNam, dispIdField, dispId, eventIdField, eventInt,'evSelect',calEvent.id,'evDomId','o_cev_' + view.name + '_' + calEvent.id);\n")
            .append("   }\n").append(" });\n")
            .append(" jQuery('.fc-header-left').append('<span class=\"fc-header-space\"></span><span id=\"")
            .append(printId)
            .append("\" class=\"fc-button fc-button-print fc-state-default fc-corner-left fc-corner-right\"><span>")
            .append(translator.translate("print")).append("</span></span>');\n")
            .append(" jQuery('.fc-button-print').click(function () {\n")
            .append(FormJSHelper.generateXHRFnCallVariables(rootForm, formId, 1))
            .append("   o_ffXHREvent(formNam, dispIdField, dispId, eventIdField, eventInt,'print','print');\n")
            .append(" });\n").append("});\n").append("/* ]]> */\n").append("</script>");
}

From source file:fr.paris.lutece.plugins.workflow.modules.rest.service.formatters.WorkflowFormatterJson.java

/**
 * {@inheritDoc }/*  w ww .j  a  v a 2 s  . c  o  m*/
 */
@Override
public String format(Workflow workflow) {
    JSONObject jsonObject = new JSONObject();

    DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, I18nService.getDefaultLocale());
    String strDate = dateFormat.format(workflow.getCreationDate());

    jsonObject.element(WorkflowRestConstants.TAG_ID_WORKFLOW, workflow.getId());
    jsonObject.element(WorkflowRestConstants.TAG_NAME, workflow.getName());
    jsonObject.element(WorkflowRestConstants.TAG_DESCRIPTION, workflow.getDescription());
    jsonObject.element(WorkflowRestConstants.TAG_CREATION_DATE, strDate);
    jsonObject.element(WorkflowRestConstants.TAG_IS_ENABLE, Boolean.toString(workflow.isEnabled()));
    jsonObject.element(WorkflowRestConstants.TAG_WORKGROUP_KEY, workflow.getWorkgroup());

    return jsonObject.toString();
}

From source file:codes.thischwa.c5c.requestcycle.response.mode.FileInfoProperties.java

private String getDate(Date date) {
    if (date == null)
        return null;
    Locale locale = RequestData.getLocale();
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    String dateStr = df.format(date);
    return dateStr;
}

From source file:pl.exsio.ca.module.config.events.EventsDataTable.java

@Override
protected void doInit() {
    super.doInit();
    Converter dateConverter = new StringToDateConverter() {
        @Override/*  ww w .jav  a 2 s .c  om*/
        protected DateFormat getFormat(Locale locale) {
            return DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
        }
    };

    this.dataComponent.setConverter("startDate", dateConverter);
    this.dataComponent.setConverter("endDate", dateConverter);
    this.dataComponent.sort(new Object[] { "startDate" }, new boolean[] { false });
}

From source file:com.robestone.hudson.compactcolumns.CompactColumnsTest.java

public void doTestDateFormats(Locale locale, int formatType, String expect) {
    DateFormat format = DateFormat.getDateInstance(formatType, locale);
    long time = 1277416568304L;
    Date date = new Date(time);
    String output = format.format(date);
    assertEquals(expect, output);//  www.  jav a  2  s .  c om
}

From source file:de.perdian.commons.lang.conversion.impl.converters.StringToDateConverter.java

@Override
protected DateFormat resolveDefaultFormat(Locale locale) {
    String pattern = this.getPattern();
    if (pattern != null) {
        return new SimpleDateFormat(pattern, locale);
    } else {//w w w .j a v a  2 s. c  o  m
        Class<? extends Date> targetDateClass = this.getTargetDateClass();
        if (targetDateClass == null || targetDateClass.equals(java.util.Date.class)
                || targetDateClass.equals(java.sql.Date.class)) {
            return DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
        } else if (targetDateClass.equals(java.sql.Timestamp.class)) {
            return DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, locale);
        } else if (targetDateClass.equals(java.sql.Time.class)) {
            return DateFormat.getTimeInstance(DateFormat.DEFAULT, locale);
        } else {
            return DateFormat.getInstance();
        }
    }
}

From source file:com.androidformenhancer.internal.impl.DatePickerDialogSupportFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle args = getArguments();/*from www .j  ava 2s .  c om*/
    int id = args.getInt(ARG_TARGET_VIEW_RES_ID);
    View v = getActivity().findViewById(id);
    if (v == null || !(v instanceof TextView)) {
        throw new IllegalArgumentException("Target view must be valid TextView: " + v);
    }
    final TextView tv = (TextView) v;
    if (TextUtils.isEmpty(tv.getText())) {
        int defaultMessageId = args.getInt(ARG_DEFAULT_MESSAGE_RES_ID);
        tv.setText(getActivity().getString(defaultMessageId));
    }

    DatePickerDialog.OnDateSetListener callBack = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            Calendar c = Calendar.getInstance(Locale.getDefault());
            c.set(Calendar.YEAR, year);
            c.set(Calendar.MONTH, monthOfYear);
            c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            tv.setText(DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()).format(c.getTime()));
        }
    };
    Calendar c = Calendar.getInstance();
    final Dialog dialog = new DatePickerDialog(getActivity(), callBack, c.get(Calendar.YEAR),
            c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)) {
    };
    return dialog;
}

From source file:lucee.commons.i18n.FormatUtil.java

public static DateFormat[] getDateFormats(Locale locale, TimeZone tz, boolean lenient) {
    String id = "d-" + locale.hashCode() + "-" + tz.getID() + "-" + lenient;
    DateFormat[] df = formats.get(id);
    if (df == null) {
        List<DateFormat> list = new ArrayList<DateFormat>();
        list.add(DateFormat.getDateInstance(DateFormat.FULL, locale));
        list.add(DateFormat.getDateInstance(DateFormat.LONG, locale));
        list.add(DateFormat.getDateInstance(DateFormat.MEDIUM, locale));
        list.add(DateFormat.getDateInstance(DateFormat.SHORT, locale));
        addCustom(list, locale, FORMAT_TYPE_DATE);
        df = list.toArray(new DateFormat[list.size()]);

        for (int i = 0; i < df.length; i++) {
            df[i].setLenient(lenient);/*from  www .j av  a2 s.co m*/
            df[i].setTimeZone(tz);
        }
        formats.put(id, df);
    }
    return df;
}

From source file:de.fau.amos4.model.Employee.java

public Map<String, String> getFields() {
    Map<String, String> allFields = new LinkedHashMap<String, String>();
    Locale locale = LocaleContextHolder.getLocale();
    DateFormat format = DateFormat.getDateInstance(DateFormat.LONG, locale);
    DateFormat df;/*from  w w  w .  ja v  a 2 s  .co  m*/
    if (locale.getLanguage().equals("de")) {
        df = new SimpleDateFormat("dd.MM.yyyy");
    } else {
        df = new SimpleDateFormat("dd/MM/yyyy");
    }

    allFields.put(AppContext.getApplicationContext().getMessage("employee.id", null, locale),
            Long.toString(getId()));
    allFields.put(AppContext.getApplicationContext().getMessage("client.companyName", null, locale),
            getClient().getCompanyName());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.personnelNumber", null, locale),
            Long.toString(getPersonnelNumber()));
    allFields.put(AppContext.getApplicationContext().getMessage("employee.firstName", null, locale),
            getFirstName());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.familyName", null, locale),
            getFamilyName());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.maidenName", null, locale),
            getMaidenName());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.birthDate", null, locale),
            format.format(getBirthDate()));
    allFields.put(AppContext.getApplicationContext().getMessage("employee.placeOfBirth", null, locale),
            getPlaceOfBirth());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.countryOfBirth", null, locale),
            getCountryOfBirth());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.street", null, locale), getStreet());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.houseNumber", null, locale),
            getHouseNumber());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.additionToAddress", null, locale),
            getAdditionToAddress());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.city", null, locale), getCity());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.zipCode", null, locale),
            getZipCode());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.sex", null, locale),
            getSex().toString());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.maritalStatus", null, locale),
            getMaritalStatus().toString());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.disabled", null, locale),
            getDisabled().toString());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.citizenship", null, locale),
            getCitizenship());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.socialInsuranceNumber", null, locale),
            getSocialInsuranceNumber());
    allFields.put(
            AppContext.getApplicationContext().getMessage("employee.employerSocialSavingsNumber", null, locale),
            getEmployerSocialSavingsNumber());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.iban", null, locale), getIban());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.bic", null, locale), getBic());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.employment", null, locale),
            getEmployment());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.temporaryEmployment", null, locale),
            getTemporaryEmployment());
    //allFields.put( AppContext.getApplicationContext().getMessage("employee.token", null, locale), getToken());
    return allFields;
}

From source file:org.olat.core.util.StringHelper.java

/**
 * @param date/*w  w w  .  ja  va  2  s.co  m*/
 * @param locale
 * @return formatted date
 */
public static String formatLocaleDate(long date, Locale locale) {
    if (date == -1)
        return "-";
    return DateFormat.getDateInstance(DateFormat.SHORT, locale).format(new Date(date));
}