List of usage examples for java.text DateFormat SHORT
int SHORT
To view the source code for java.text DateFormat SHORT.
Click Source Link
From source file:org.olat.user.restapi.UserVOFactory.java
/** * Allow the date to be in the localized form or not * @param value//from ww w . ja va2 s . co m * @param handler * @param locale * @return */ public static final String formatDbDate(String value, Locale locale) { if (!StringHelper.containsNonWhitespace(value)) { return value; } boolean raw = true; for (int i = 0; i < value.length(); i++) { if (!Character.isDigit(value.charAt(i))) { raw = false; break; } } if (raw) { return value; } try { DateFormat outFormater = new SimpleDateFormat("yyyyMMdd", Locale.GERMAN); DateFormat inFormater = DateFormat.getDateInstance(DateFormat.SHORT, locale); Date date = inFormater.parse(value); value = outFormater.format(date); } catch (ParseException e) { /* silently failed */ } return value; }
From source file:org.opencms.i18n.CmsMessages.java
/** * Returns a formated date String from a timestamp value, * the format being {@link DateFormat#SHORT} and the locale * based on this instance.<p>/*from w w w. j a v a 2s. c o m*/ * * @param time the time value to format as date * @return the formatted date */ public String getDate(long time) { return CmsDateUtil.getDate(new Date(time), DateFormat.SHORT, m_locale); }
From source file:fit.Fixture.java
public Object parse(String s, Class<?> type) throws Exception { if (type.equals(String.class)) { if (s.toLowerCase().equals("null")) return null; else if (s.toLowerCase().equals("blank")) return ""; else//from www . j a v a 2 s . c om return s; } else if (type.equals(Date.class)) { return DateFormat.getDateInstance(DateFormat.SHORT).parse(s); } else if (hasParseMethod(type)) { return callParseMethod(type, s); } else { throw new CouldNotParseFitFailureException(s, type.getName()); } }
From source file:org.mifos.framework.util.helpers.DateUtils.java
public static String getLocalDateString(DateTime date, Locale locale) throws InvalidDateException { // the following line is for 1.1 release and will be removed when date // is localized locale = internalLocale;// w ww. ja v a2 s . c o m Calendar calendar = date.toCalendar(locale); java.sql.Date currentDate = new java.sql.Date(calendar.getTimeInMillis()); SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale); String userfmt = convertToCurrentDateFormat(format.toPattern()); return convertDbToUserFmt(currentDate.toString(), userfmt); }
From source file:de.langerhans.wallet.ui.ImportKeysQrFragment.java
private void updateDate(final int year, final int month, final int day) { calendar.set(year, month, day, 0, 0); date.setText(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(calendar.getTime())); }
From source file:org.opencms.i18n.CmsMessages.java
/** * Returns a formated date and time String from a Date value, * the format being {@link DateFormat#SHORT} and the locale * based on this instance.<p>//from w w w .j a v a 2 s. c o m * * @param date the Date object to format as String * @return the formatted date and time */ public String getDateTime(Date date) { return CmsDateUtil.getDateTime(date, DateFormat.SHORT, m_locale); }
From source file:de.langerhans.wallet.ui.ImportKeysQrFragment.java
private void updateDate(final long timeSeconds) { calendar.setTimeInMillis(timeSeconds * 1000); date.setText(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(calendar.getTime())); }
From source file:org.sakaiproject.signup.tool.jsf.organizer.action.SignupAction.java
public String generateGroupTitle(String meetingTitle, SignupTimeslot timeslot, int rowNum) { //Based on the database limitation final int TITLE_MAX_LENGTH = 99; final char SEPARATOR = '-'; final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); int titleSize = TITLE_MAX_LENGTH - SakaiFacade.GROUP_PREFIX.length(); String dateString = df.format(timeslot.getStartTime()); StringBuilder sb = new StringBuilder(titleSize); sb.append(" "); sb.append(SEPARATOR);//ww w . j a v a 2s. c om sb.append(Utilities.rb.getString("group_slot_in_group_titlename")); sb.append(" " + rowNum); titleSize -= sb.length(); //take the dateString length away with " _" prefix, it fixed recurring events duplicate groupName issue titleSize -= dateString.length() + 2; if (titleSize > 0) sb.insert(0, meetingTitle.substring(0, Math.min(titleSize, meetingTitle.length()))); //fixes recurring meeting with the same tile, which causes the same groupName sb.append(" _" + dateString); return sb.toString(); }
From source file:org.lbogdanov.poker.web.page.SessionPage.java
private String formatDate(Date created) { final long MILLIS_PER_WEEK = TimeUnit.DAYS.toMillis(7); Locale locale = getLocale();// w w w.j av a2s . co m PrettyTime prettyTime = new PrettyTime(locale); Duration largest = Iterables.getFirst(prettyTime.calculatePreciseDuration(created), null); if (largest != null && largest.getUnit().getMillisPerUnit() < MILLIS_PER_WEEK) { return prettyTime.format(largest); } else { // fallback to an absolute date string when difference is more than a week return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale).format(created); } }
From source file:org.exoplatform.outlook.social.OutlookMessageActivity.java
/** * {@inheritDoc}/* w ww.j av a 2s . com*/ */ @Override public String getSummary(Node node) { try { if (node.isNodeType(OutlookService.MESSAGE_NODETYPE)) { String fromEmail = node.getProperty("mso:fromEmail").getString(); String fromName = node.getProperty("mso:fromName").getString(); Date time = node.getProperty("mso:created").getDate().getTime(); Locale userLocale = null; RequestContext context = RequestContext.getCurrentInstance(); OrganizationService orgService = getApplicationComponent(OrganizationService.class); try { UserProfile userProfile = orgService.getUserProfileHandler() .findUserProfileByName(context.getRemoteUser()); if (userProfile != null) { String lang = userProfile.getUserInfoMap().get(Constants.USER_LANGUAGE); if (lang != null) { userLocale = LocaleContextInfo.getLocale(lang); } } else if (LOG.isDebugEnabled()) { LOG.debug("User profile not found for " + context.getRemoteUser()); } } catch (Exception e) { LOG.warn("Error getting user profile for " + context.getRemoteUser(), e); } if (userLocale == null) { // try find locale from user request if (PortletRequestContext.class.isAssignableFrom(context.getClass())) { userLocale = ((PortalRequestContext) PortletRequestContext.class.cast(context) .getParentAppRequestContext()).getRequest().getLocale(); } else if (PortalRequestContext.class.isAssignableFrom(context.getClass())) { userLocale = PortalRequestContext.class.cast(context).getRequest().getLocale(); } if (userLocale == null) { // it's server locale in most cases userLocale = context.getLocale(); if (userLocale == null) { userLocale = Locale.ENGLISH; } } } DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL, userLocale); DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, userLocale); ResourceBundle res = context.getApplicationResourceBundle(); StringBuilder fromLine = new StringBuilder(); fromLine.append(fromName); fromLine.append('<'); fromLine.append(fromEmail); fromLine.append('>'); StringBuilder summary = new StringBuilder(); summary.append(res.getString("Outlook.activity.from")); summary.append(": <a href='mailto:"); summary.append(fromEmail); summary.append("' target='_top'>"); summary.append(ContentReader.simpleEscapeHtml(fromLine.toString())); summary.append("</a> "); summary.append(res.getString("Outlook.activity.on")); summary.append(' '); summary.append(dateFormat.format(time)); summary.append(' '); summary.append(res.getString("Outlook.activity.at")); summary.append(' '); summary.append(timeFormat.format(time)); return summary.toString(); } } catch (RepositoryException e) { LOG.warn("Error generating info for Outlook message activity node " + node, e); } return super.getSummary(node); }