Example usage for com.google.gwt.i18n.client DateTimeFormat getShortTimeFormat

List of usage examples for com.google.gwt.i18n.client DateTimeFormat getShortTimeFormat

Introduction

In this page you can find the example usage for com.google.gwt.i18n.client DateTimeFormat getShortTimeFormat.

Prototype

@Deprecated
public static DateTimeFormat getShortTimeFormat() 

Source Link

Document

Retrieve the DateTimeFormat object for short time format.

Usage

From source file:com.google.gwt.examples.DateTimeFormatExample.java

public void onModuleLoad() {
    Date today = new Date();

    // prints Tue Dec 18 12:01:26 GMT-500 2007 in the default locale.
    GWT.log(today.toString());//from ww  w  . j  a  va  2 s  .c o  m

    // prints 12/18/07 in the default locale
    GWT.log(DateTimeFormat.getShortDateFormat().format(today));

    // prints December 18, 2007 in the default locale
    GWT.log(DateTimeFormat.getLongDateFormat().format(today));

    // prints 12:01 PM in the default locale
    GWT.log(DateTimeFormat.getShortTimeFormat().format(today));

    // prints 12:01:26 PM GMT-05:00 in the default locale
    GWT.log(DateTimeFormat.getLongTimeFormat().format(today));

    // prints Dec 18, 2007 12:01:26 PM in the default locale
    GWT.log(DateTimeFormat.getMediumDateTimeFormat().format(today));

    // A custom date format
    DateTimeFormat fmt = DateTimeFormat.getFormat("EEEE, MMMM dd, yyyy");
    // prints Monday, December 17, 2007 in the default locale
    GWT.log(fmt.format(today));
}

From source file:com.google.gwt.sample.i18n.client.DateTimeFormatExampleController.java

License:Apache License

@Override
protected String doGetPattern(String patternKey) {
    // Date + Time
    if ("fullDateTime".equals(patternKey)) {
        return DateTimeFormat.getFullDateTimeFormat().getPattern();
    }/*from   w ww . ja  v a  2  s.  c  o  m*/

    if ("longDateTime".equals(patternKey)) {
        return DateTimeFormat.getLongDateTimeFormat().getPattern();
    }

    if ("mediumDateTime".equals(patternKey)) {
        return DateTimeFormat.getMediumDateTimeFormat().getPattern();
    }

    if ("shortDateTime".equals(patternKey)) {
        return DateTimeFormat.getShortDateTimeFormat().getPattern();
    }

    // Date only
    if ("fullDate".equals(patternKey)) {
        return DateTimeFormat.getFullDateFormat().getPattern();
    }

    if ("longDate".equals(patternKey)) {
        return DateTimeFormat.getLongDateFormat().getPattern();
    }

    if ("mediumDate".equals(patternKey)) {
        return DateTimeFormat.getMediumDateFormat().getPattern();
    }

    if ("shortDate".equals(patternKey)) {
        return DateTimeFormat.getShortDateFormat().getPattern();
    }

    // Time only
    if ("fullTime".equals(patternKey)) {
        return DateTimeFormat.getFullTimeFormat().getPattern();
    }

    if ("longTime".equals(patternKey)) {
        return DateTimeFormat.getLongTimeFormat().getPattern();
    }

    if ("mediumTime".equals(patternKey)) {
        return DateTimeFormat.getMediumTimeFormat().getPattern();
    }

    if ("shortTime".equals(patternKey)) {
        return DateTimeFormat.getShortTimeFormat().getPattern();
    }

    throw new IllegalArgumentException("Unknown pattern key '" + patternKey + "'");
}

From source file:com.jawspeak.gwt.verysimpletemplate.client.template.DefaultDateFormatter.java

License:Apache License

public static String formatDateToStandard(Date date) {
    return DateTimeFormat.getShortDateFormat().format(date) + " "
            + DateTimeFormat.getShortTimeFormat().format(date);
}

From source file:fr.aliasource.webmail.client.reader.invitation.InvitationPanel.java

License:GNU General Public License

private VerticalPanel fillInfoEventPanel() {
    VerticalPanel vp = new VerticalPanel();
    vp.setStyleName("detailEvent noWrap");
    Label lb = new Label(strings.newEvent());
    vp.add(lb);//from  w w w .  j ava2  s . com

    this.infoEventPanel = new FlexTable();
    infoEventPanel.addStyleName("leftPanel");
    infoEventPanel.setText(0, 0, strings.invitationTitle() + ":");
    infoEventPanel.setText(0, 1, invitationInfo.getEvent().getTitle());

    infoEventPanel.setText(1, 0, strings.invitationOwner() + ":");
    infoEventPanel.setText(1, 1, invitationInfo.getEvent().getOwner());

    infoEventPanel.setText(2, 0, strings.invitationWhen() + ":");

    if (invitationInfo.getEvent().getDtStart() != null) {
        DateTimeFormat dtfStart = DateTimeFormat.getShortDateTimeFormat();
        String sStart = dtfStart.format(invitationInfo.getEvent().getDtStart());

        DateTimeFormat dtfEnd = DateTimeFormat.getShortTimeFormat();
        String sEnd = dtfEnd.format(invitationInfo.getEvent().getDtEnd());

        infoEventPanel.setText(2, 1, sStart + " - " + sEnd);
    }

    infoEventPanel.setText(3, 0, strings.invitationWhere() + ":");
    infoEventPanel.setText(3, 1, invitationInfo.getEvent().getLocation());

    String who = getWho();
    if (!"".endsWith(who)) {
        infoEventPanel.setText(4, 0, strings.invitationWho() + ":");
        infoEventPanel.setText(4, 1, who);
    }

    Element moreDetail = DOM.createElement("a");
    moreDetail.setAttribute("href", invitationInfo.getCalendarUrl());
    moreDetail.setInnerText(strings.moreActions());
    HTML linkMoreDetail = new HTML();
    linkMoreDetail.getElement().appendChild(moreDetail);

    infoEventPanel.setWidget(5, 1, linkMoreDetail);

    accept = getGoingLink(strings.invitationYes(), "invitationYes", INVITATION_ACCEPT);
    maybe = getGoingLink(strings.invitationMaybe(), "invitationMaybe", INVITATION_MAYBE);
    refuse = getGoingLink(strings.invitationNo(), "invitationNo", INVITATION_REFUSE);
    updateGoingLink("");

    for (int i = 0; i < infoEventPanel.getRowCount(); ++i) {
        infoEventPanel.getCellFormatter().setStyleName(i, 0, "keys");
    }
    infoEventPanel.getRowFormatter().addStyleName(0, "titleEvent");
    infoEventPanel.getRowFormatter().addStyleName(1, "ownerEvent");
    infoEventPanel.getRowFormatter().addStyleName(2, "startEvent");

    vp.add(infoEventPanel);
    return vp;
}

From source file:fr.aliasource.webmail.client.reader.invitation.InvitationPanel.java

License:GNU General Public License

private VerticalPanel fillAgendaPanel() {
    agendaPanel = new VerticalPanel();
    agendaPanel.setStyleName("agendaPanel");
    agendaPanel.setBorderWidth(1);/*from w w  w.j a v a2s .co  m*/
    if (invitationInfo.getEvent().getDtStart() != null) {
        Date when = invitationInfo.getEvent().getDtStart();
        DateTimeFormat dtf = DateTimeFormat.getMediumDateFormat();
        HTML day = new HTML(strings.invitationDay(dtf.format(when)));
        day.setStyleName("invitationDay");
        agendaPanel.add(day);
    }

    for (SimpleEvent sEvent : invitationInfo.getEventOfDay()) {
        String sStart = "";
        if (sEvent.isAllDay()) {
            sStart = strings.eventAllDay();
        } else if (sEvent.getStart() != null) {
            DateTimeFormat dtfStart = DateTimeFormat.getShortTimeFormat();
            sStart = dtfStart.format(sEvent.getStart());
        }
        InvitationAgendaLine line = new InvitationAgendaLine(sStart, sEvent.getTitle());
        agendaPanel.add(line);

    }

    Anchor a = new Anchor(strings.invitationGoToCalendar());
    a.setHref(invitationInfo.getCalendarUrl());
    a.setTarget("_blank");
    agendaPanel.add(a);

    return agendaPanel;
}

From source file:java.text.DateFormat.java

License:Apache License

public final static DateFormat getTimeInstance(int style) {
    switch (style) {
    case FULL://w w  w.jav a 2  s .  co m
        return new SimpleDateFormat(DateTimeFormat.getFullTimeFormat());
    case LONG:
        return new SimpleDateFormat(DateTimeFormat.getLongTimeFormat());
    case SHORT:
        return new SimpleDateFormat(DateTimeFormat.getShortTimeFormat());
    default:
        return getTimeInstance();
    }
}

From source file:net.s17fabu.vip.gwt.showcase.client.content.i18n.CwDateTimeFormat.java

License:Apache License

/**
 * Update the selected pattern based on the pattern in the list.
 */// w w w  .  ja  v  a2  s.  c  om
private void updatePattern() {
    switch (patternList.getSelectedIndex()) {
    // Date + Time
    case 0:
        activeFormat = DateTimeFormat.getFullDateTimeFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;

    case 1:
        activeFormat = DateTimeFormat.getLongDateTimeFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;
    case 2:
        activeFormat = DateTimeFormat.getMediumDateTimeFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;
    case 3:
        activeFormat = DateTimeFormat.getShortDateTimeFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;

    // Date only
    case 4:
        activeFormat = DateTimeFormat.getFullDateFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;

    case 5:
        activeFormat = DateTimeFormat.getLongDateFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;
    case 6:
        activeFormat = DateTimeFormat.getMediumDateFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;
    case 7:
        activeFormat = DateTimeFormat.getShortDateFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;

    // Time only
    case 8:
        activeFormat = DateTimeFormat.getFullTimeFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;

    case 9:
        activeFormat = DateTimeFormat.getLongTimeFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;
    case 10:
        activeFormat = DateTimeFormat.getMediumTimeFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;
    case 11:
        activeFormat = DateTimeFormat.getShortTimeFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;

    // Custom
    case 12:
        patternBox.setEnabled(true);
        String pattern = patternBox.getText();
        try {
            activeFormat = DateTimeFormat.getFormat(pattern);
        } catch (IllegalArgumentException e) {
            showErrorMessage(constants.cwDateTimeFormatInvalidPattern());
            return;
        }
        break;
    }

    // Update the formatted value
    updateFormattedValue();
}

From source file:org.waveprotocol.wave.client.common.util.DateUtils.java

License:Apache License

/**
 * Formats the specified time as a String.
 *//*w w w.  ja va2s .c om*/
public String formatTime(Date date) {
    // NOTE(zdwang): For now skip it for junit code; also see formatPastDate()
    if (!GWT.isClient()) {
        return "formatDateTime is not yet implemented in unit test code";
    }

    // AM/PM -> am/pm for consistency with formatPastDate()
    return DateTimeFormat.getShortTimeFormat().format(date).toLowerCase();
}