Example usage for java.text DateFormat SHORT

List of usage examples for java.text DateFormat SHORT

Introduction

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

Prototype

int SHORT

To view the source code for java.text DateFormat SHORT.

Click Source Link

Document

Constant for short style pattern.

Usage

From source file:org.apache.camel.web.util.JMXRouteStatistics.java

@SuppressWarnings("unchecked")
public Object getRouteStatistic(CamelContext camelContext, String routeID, String attribute) {
    // only possible if JMX is enabled
    if (!(camelContext.getManagementStrategy() instanceof ManagedManagementStrategy)) {
        return null;
    }//from   w ww. j  av a2  s.c  om

    try {
        MBeanServer server = camelContext.getManagementStrategy().getManagementAgent().getMBeanServer();
        String domain = camelContext.getManagementStrategy().getManagementAgent().getMBeanObjectDomainName();

        ObjectName objName = new ObjectName(domain + ":type=routes,*");
        List<ObjectName> cacheList = new LinkedList(server.queryNames(objName, null));
        for (Iterator<ObjectName> iter = cacheList.iterator(); iter.hasNext();) {
            objName = iter.next();
            String keyProps = objName.getCanonicalKeyPropertyListString();
            ObjectName objectInfoName = new ObjectName(domain + ":" + keyProps);
            String currentRouteID = (String) server.getAttribute(objectInfoName, "RouteId");
            if (currentRouteID.equals(routeID)) {
                Object value = server.getAttribute(objectInfoName, attribute);
                if (value instanceof Date) {
                    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
                    return df.format(value);
                } else {
                    return value;
                }
            }
        }
    } catch (Exception e) {
        LOG.warn("Error getting route statistic from JMX. This exception will be ignored.", e);
    }

    return null;
}

From source file:org.webical.web.converters.DateStringConverter.java

public String convertToString(Object value, Locale locale) {
    if (value == null) {
        return null;
    }/*from  w  w w  . j a  v a2s  .  c  o m*/

    Date date = (Date) value;

    String result;
    if (useDate) {
        result = DateFormat.getDateInstance(DateFormat.SHORT, getLocale()).format(date);
    } else {
        result = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, getLocale()).format(date);
    }

    return result;
}

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

public void testDateFormats() {
    doTestDateFormats(Locale.US, DateFormat.SHORT, "6/24/10");
    doTestDateFormats(Locale.US, DateFormat.MEDIUM, "Jun 24, 2010");
    doTestDateFormats(Locale.GERMAN, DateFormat.SHORT, "24.06.10");
}

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  w  w .  ja v  a 2s.  c o  m
    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 }/*from   ww  w.  ja  va 2 s  .com*/
 */
@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:at.becast.youploader.youtube.GuiUploadEvent.java

@Override
public void onInit() {
    this.starttime = System.currentTimeMillis();
    this.lastdata = 0;
    this.lasttime = this.starttime;
    this.lastdb = this.starttime;
    Date in = new Date(this.starttime);
    LocalDateTime ldt = LocalDateTime.ofInstant(in.toInstant(), ZoneId.systemDefault());
    Date out = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT,
            Locale.getDefault());
    frame.getlblStart().setText(formatter.format(out));
    frame.getProgressBar().setString("0,00 %");
    frame.getProgressBar().setValue(0);/*ww  w .  j av  a2 s . c o  m*/
    frame.getProgressBar().revalidate();
    frame.getBtnCancel().setEnabled(true);
    frame.getBtnEdit().setEnabled(true);
    frame.getBtnDelete().setEnabled(false);
    frame.revalidate();
    frame.repaint();
}

From source file:org.opencms.workplace.comparison.CmsResourceComparison.java

/**
 * Helper method that collects all meta attributes of the two file versions and 
 * finds out, which of the attributes were added, removed, modified or remain unchanged.<p>
 * //www  .ja  v a  2 s .com
 * @param cms the CmsObject to use
 * @param resource1 the first resource to read the properties from
 * @param resource2 the second resource to read the properties from
 * 
 * @return a list of the compared attributes
 */
public static List compareAttributes(CmsObject cms, CmsResource resource1, CmsResource resource2) {

    List comparedAttributes = new ArrayList();
    comparedAttributes.add(new CmsAttributeComparison(Messages.GUI_HISTORY_COLS_SIZE_0,
            String.valueOf(resource1.getLength()), String.valueOf(resource2.getLength())));
    String release1;
    if (CmsResource.DATE_RELEASED_DEFAULT == resource1.getDateReleased()) {
        release1 = "-";
    } else {
        release1 = CmsDateUtil.getDateTime(new Date(resource1.getDateReleased()), DateFormat.SHORT,
                cms.getRequestContext().getLocale());
    }
    String release2;
    if (CmsResource.DATE_RELEASED_DEFAULT == resource2.getDateReleased()) {
        release2 = "-";
    } else {
        release2 = CmsDateUtil.getDateTime(new Date(resource2.getDateReleased()), DateFormat.SHORT,
                cms.getRequestContext().getLocale());
    }
    comparedAttributes.add(new CmsAttributeComparison(Messages.GUI_LABEL_DATE_RELEASED_0, release1, release2));
    String expire1;
    if (CmsResource.DATE_EXPIRED_DEFAULT == resource1.getDateExpired()) {
        expire1 = "-";
    } else {
        expire1 = CmsDateUtil.getDateTime(new Date(resource1.getDateExpired()), DateFormat.SHORT,
                cms.getRequestContext().getLocale());
    }
    String expire2;
    if (CmsResource.DATE_EXPIRED_DEFAULT == resource2.getDateExpired()) {
        expire2 = "-";
    } else {
        expire2 = CmsDateUtil.getDateTime(new Date(resource2.getDateExpired()), DateFormat.SHORT,
                cms.getRequestContext().getLocale());
    }
    comparedAttributes.add(new CmsAttributeComparison(Messages.GUI_LABEL_DATE_EXPIRED_0, expire1, expire2));
    comparedAttributes.add(new CmsAttributeComparison(Messages.GUI_PERMISSION_INTERNAL_0,
            String.valueOf(resource1.isInternal()), String.valueOf(resource2.isInternal())));
    String dateLastModified1 = CmsDateUtil.getDateTime(new Date(resource1.getDateLastModified()),
            DateFormat.SHORT, cms.getRequestContext().getLocale());
    String dateLastModified2 = CmsDateUtil.getDateTime(new Date(resource2.getDateLastModified()),
            DateFormat.SHORT, cms.getRequestContext().getLocale());
    comparedAttributes.add(new CmsAttributeComparison(Messages.GUI_LABEL_DATE_LAST_MODIFIED_0,
            dateLastModified1, dateLastModified2));
    try {
        String type1 = OpenCms.getResourceManager().getResourceType(resource1.getTypeId()).getTypeName();
        String type2 = OpenCms.getResourceManager().getResourceType(resource2.getTypeId()).getTypeName();
        comparedAttributes.add(new CmsAttributeComparison(Messages.GUI_HISTORY_COLS_FILE_TYPE_0, type1, type2));
    } catch (CmsLoaderException e) {
        LOG.debug(e.getMessage(), e);
    }
    String dateCreated1 = CmsDateUtil.getDateTime(new Date(resource1.getDateCreated()), DateFormat.SHORT,
            cms.getRequestContext().getLocale());
    String dateCreated2 = CmsDateUtil.getDateTime(new Date(resource2.getDateCreated()), DateFormat.SHORT,
            cms.getRequestContext().getLocale());
    comparedAttributes.add(
            new CmsAttributeComparison(Messages.GUI_HISTORY_COLS_DATE_PUBLISHED_0, dateCreated1, dateCreated2));
    try {
        String userLastModified1 = resource1.getUserLastModified().toString();
        try {
            userLastModified1 = CmsPrincipal.readPrincipalIncludingHistory(cms, resource1.getUserLastModified())
                    .getName();
        } catch (CmsDbEntryNotFoundException e) {
            // ignore
        }
        String userLastModified2 = resource2.getUserLastModified().toString();
        try {
            userLastModified2 = CmsPrincipal.readPrincipalIncludingHistory(cms, resource2.getUserLastModified())
                    .getName();
        } catch (CmsDbEntryNotFoundException e) {
            // ignore
        }
        comparedAttributes.add(new CmsAttributeComparison(Messages.GUI_LABEL_USER_LAST_MODIFIED_0,
                userLastModified1, userLastModified2));
    } catch (CmsException e) {
        LOG.error(e.getMessage(), e);
    }
    String path1 = cms.getRequestContext().removeSiteRoot(resource1.getRootPath());
    String path2 = cms.getRequestContext().removeSiteRoot(resource2.getRootPath());
    comparedAttributes.add(new CmsAttributeComparison(Messages.GUI_HISTORY_COLS_RESOURCE_PATH_0, path1, path2));
    return comparedAttributes;
}

From source file:org.kuali.kra.irb.protocol.reference.ProtocolReferenceRule.java

private boolean validateDate(String stringDate) {
    try {/*from   w  w  w .  ja  v  a2  s.  co  m*/
        if (!StringUtils.isBlank(stringDate)) {
            Date date = new Date(DateFormat.getDateInstance(DateFormat.SHORT).parse(stringDate).getTime());
        }
    } catch (ParseException e) {
        return false;
    }
    return true;
}

From source file:ca.uvic.cs.tagsea.wizards.TagNetworkSender.java

private static String getToday() {
    Date today = new Date(System.currentTimeMillis());
    String todayString = DateFormat.getDateInstance(DateFormat.SHORT).format(today);
    todayString = todayString.replace('/', '_');
    todayString = todayString.replace('\\', '-');
    todayString = todayString.replace('.', '_');
    todayString = todayString.replace(':', '_');
    todayString = todayString.replace(';', '_');
    return todayString;
}

From source file:org.wso2.carbon.core.services.loggeduserinfo.LoggedUserInfoAdmin.java

public LoggedUserInfo getUserInfo() throws Exception {
    try {// www .  jav a  2s.  c  o  m
        MessageContext messageContext = MessageContext.getCurrentMessageContext();
        HttpServletRequest request = (HttpServletRequest) messageContext
                .getProperty("transport.http.servletRequest");
        String userName = (String) request.getSession().getAttribute(ServerConstants.USER_LOGGED_IN);

        int index = userName.indexOf("/");
        if (index < 0) {
            String domainName = (String) request.getSession()
                    .getAttribute(CarbonAuthenticationUtil.LOGGED_IN_DOMAIN);

            if (domainName != null) {
                userName = domainName + "/" + userName;
            }
        }
        LoggedUserInfo loggedUserInfo = new LoggedUserInfo();
        UserRealm userRealm = (UserRealm) PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm();
        List<String> userPermissions = getUserPermissions(userName, userRealm);
        String[] permissions = userPermissions.toArray(new String[userPermissions.size()]);
        loggedUserInfo.setUIPermissionOfUser(permissions);
        Date date = userRealm.getUserStoreManager().getPasswordExpirationTime(userName);
        loggedUserInfo.setUserName(userName);
        if (date != null) {
            DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
            DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
            String passwordExpiration = timeFormat.format(date) + " on " + dateFormat.format(date);
            loggedUserInfo.setPasswordExpiration(passwordExpiration);
        }
        return loggedUserInfo;
    } catch (Exception e) {
        log.error(e);
        throw e;
    }
}