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:DateFormatDemo.java

static public void showDateStyles(Locale currentLocale) {

    Date today = new Date();
    String result;//from w ww .  j  av  a 2 s . c  o  m
    DateFormat formatter;

    int[] styles = { DateFormat.DEFAULT, DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG,
            DateFormat.FULL };

    System.out.println();
    System.out.println("Locale: " + currentLocale.toString());
    System.out.println();

    for (int k = 0; k < styles.length; k++) {
        formatter = DateFormat.getDateInstance(styles[k], currentLocale);
        result = formatter.format(today);
        System.out.println(result);
    }
}

From source file:org.kuali.student.ap.coursesearch.util.TimestampPropertyEditor.java

@Override
public String getAsText() {
    Date date = (Date) super.getValue();

    if (null == date) {
        return this.emptyDateText;
    }/*from ww  w . j  av a  2  s .  c o m*/

    if (this.simpleDateFormat.length() == 0) {
        return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date);
    } else {
        KSDateTimeFormatter format = new KSDateTimeFormatter(simpleDateFormat);
        return format.format(date);
    }
}

From source file:com.oldsneerjaw.sleeptimer.CountdownNotifierTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();

    Context mockContext = Mockito.mock(Context.class);
    Mockito.when(mockContext.getPackageName()).thenReturn("com.oldsneerjaw.sleeptimer");
    Mockito.when(mockContext.getApplicationContext()).thenReturn(mockContext);

    mockNotificationManager = Mockito.mock(NotificationManager.class);

    Resources mockResources = Mockito.mock(Resources.class);
    Mockito.when(mockResources.getString(R.string.countdown_notification_title)).thenReturn(NOTIFICATION_TITLE);
    Mockito.when(mockResources.getString(R.string.countdown_notification_text)).thenReturn(NOTIFICATION_TEXT);

    mockCountdownTimeFormatFactory = Mockito.mock(CountdownNotifier.TimeFormatFactory.class);
    Mockito.when(mockCountdownTimeFormatFactory.getTimeFormat())
            .thenReturn(DateFormat.getTimeInstance(DateFormat.SHORT));

    notifier = new CountdownNotifier(mockContext, mockNotificationManager, mockResources,
            mockCountdownTimeFormatFactory);
}

From source file:edu.illinois.my.wiki.services.WikiLocationImpl.java

@Override
public String getLastModificationDateString() {
    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT);
    Date modifiedDate = getLastModificationDate();
    return formatter.format(modifiedDate);
}

From source file:com.liferay.social.model.Contact.java

private DateFormat _getDateFormatter() {
    if (_dateFormatter == null) {
        _dateFormatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    }//w ww. j av a2s .c  o  m

    return _dateFormatter;
}

From source file:org.kuali.student.myplan.course.util.TimestampPropertyEditor.java

@Override
public String getAsText() {
    Date date = (Date) super.getValue();

    if (null == date) {
        return this.emptyDateText;
    }//from w w  w .  ja v a  2s . c  om

    if (this.simpleDateFormat.length() == 0) {
        return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date);
    } else if (isPlanAuditSummaryFormat()) {
        SimpleDateFormat monthFormat = new SimpleDateFormat("MMM");
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd");
        SimpleDateFormat timeFormat = new SimpleDateFormat("h:mm aa");
        return wrapInHtml(monthFormat.format(date), dateFormat.format(date), timeFormat.format(date));
    } else {
        SimpleDateFormat format = new SimpleDateFormat(simpleDateFormat);
        return format.format(date);
    }

}

From source file:org.openvpms.web.resource.i18n.format.DateFormatter.java

/**
 * Returns a date format.//from ww w . j a  v a  2  s  .c  o  m
 *
 * @param edit if {@code true} return a format for editing otherwise return a format for viewing dates
 * @return a date format
 */
public static DateFormat getDateFormat(boolean edit) {
    DateFormat format;
    Locale locale = Messages.getLocale();
    String pattern = (edit) ? DATE_EDIT_PATTERN : DATE_VIEW_PATTERN;
    if (pattern == null) {
        if (edit) {
            // specify SHORT style when parsing, so that 2 digit years
            // are handled correctly
            format = DateFormat.getDateInstance(DateFormat.SHORT, locale);
        } else {
            format = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
        }
    } else {
        format = new SimpleDateFormat(pattern, locale);
    }
    return format;
}

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

public Object convertToObject(String value, Locale locale) {
    if (!(value instanceof String) || StringUtils.isEmpty(value)) {
        return null;
    }/*from   ww w.  j av  a2 s . co  m*/

    String dateString = (String) value;
    try {
        if (useDate) {
            return DateFormat.getDateInstance(DateFormat.SHORT, getLocale()).parse(dateString);
        } else {
            return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, getLocale())
                    .parse(dateString);
        }
    } catch (ParseException e) {
        throw new ConversionException("'" + value + "' is not a Date");
    }
}

From source file:com.lovejoy777sarootool.rootool.adapters.BrowserListAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder mViewHolder;
    int num_items = 0;
    final File file = new File(getItem(position));
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault());

    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.item_browserlist, parent, false);
        mViewHolder = new ViewHolder(convertView);
        convertView.setTag(mViewHolder);
    } else {/*w w w .java  2s.  c  o  m*/
        mViewHolder = (ViewHolder) convertView.getTag();
    }

    if (Settings.mListAppearance > 0) {
        mViewHolder.dateview.setVisibility(TextView.VISIBLE);
    } else {
        mViewHolder.dateview.setVisibility(TextView.GONE);
    }

    // get icon
    IconPreview.getFileIcon(file, mViewHolder.icon);

    if (file.isFile()) {
        // Shows the size of File
        mViewHolder.bottomView.setText(FileUtils.byteCountToDisplaySize(file.length()));
    } else {
        String[] list = file.list();

        if (list != null)
            num_items = list.length;

        // show the number of files in Folder
        mViewHolder.bottomView.setText(num_items + mResources.getString(R.string.files));
    }

    mViewHolder.topView.setText(file.getName());
    mViewHolder.dateview.setText(df.format(file.lastModified()));

    return convertView;
}

From source file:fr.paris.lutece.plugins.grusupply.service.GruSupplyPlugin.java

/**
 * {@inheritDoc}/*from   w w w  .  ja v  a 2 s .  c om*/
 */
@Override
public void init() {
    BeanUtilsBean.getInstance().getConvertUtils().register(
            new DateConverter(DateFormat.getDateInstance(DateFormat.SHORT, Locale.FRANCE)),
            java.sql.Date.class);
}