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.apache.accumulo.monitor.servlets.TServersServlet.java
public static void doDeadServerTable(HttpServletRequest req, StringBuilder sb, Table deadTServerList, List<DeadServer> obit) { if (obit != null && !obit.isEmpty()) { deadTServerList.addSortableColumn("Server"); deadTServerList.addSortableColumn("Last Updated", new DateTimeType(DateFormat.MEDIUM, DateFormat.SHORT), null); deadTServerList.addSortableColumn("Event"); deadTServerList.addUnsortableColumn("Clear"); for (DeadServer dead : obit) deadTServerList.addRow(TServerLinkType.displayName(dead.server), dead.lastStatus, dead.status, "<a href='/op?action=clearDeadServer&redir=" + currentPage(req) + "&server=" + encode(dead.server) + "'>clear</a>"); deadTServerList.generate(req, sb); }/* w w w. ja v a2 s .c o m*/ }
From source file:org.totschnig.myexpenses.util.Utils.java
public static DateFormat localizedYearlessDateFormat() { Locale l = Locale.getDefault(); String yearlessPattern = ((SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, l)).toPattern() .replaceAll("\\W?[Yy]+\\W?", ""); return new SimpleDateFormat(yearlessPattern, l); }
From source file:org.svij.taskwarriorapp.activities.TaskAddActivity.java
@Override public void onDateSet(CalendarDatePickerDialog dialog, int year, int monthOfYear, int dayOfMonth) { TextView tvDueTime = (TextView) findViewById(R.id.tvDueTime); if (TextUtils.isEmpty(tvDueTime.getText().toString())) { cal = new GregorianCalendar(year, monthOfYear, dayOfMonth); } else {/* w w w . j a v a 2 s.com*/ cal.set(year, monthOfYear, dayOfMonth); } timestamp = cal.getTimeInMillis(); TextView etTaskDate = (TextView) findViewById(R.id.tvDueDate); etTaskDate.setText(DateFormat.getDateInstance(DateFormat.SHORT).format(timestamp)); }
From source file:org.olat.core.commons.modules.bc.components.ListRenderer.java
/** * Render a single file or folder./* w w w . j av a 2 s.co m*/ * * @param f The file or folder to render * @param sb StringOutput to append generated html code */ private void appendRenderedFile(FolderComponent fc, VFSItem child, String currentContainerPath, StringOutput sb, URLBuilder ubu, Translator translator, boolean iframePostEnabled, boolean canContainerVersion, Map<Long, Identity> identityMap, int pos) { // asume full access unless security callback tells us something different. boolean canWrite = child.getParentContainer().canWrite() == VFSConstants.YES; boolean canDelete = child.getParentContainer().canDelete() == VFSConstants.YES; boolean isAbstract = (child instanceof AbstractVirtualContainer); Versions versions = null; if (canContainerVersion && child instanceof Versionable) { Versionable versionable = (Versionable) child; if (versionable.getVersions().isVersioned()) { versions = versionable.getVersions(); } } boolean canVersion = versions != null && !versions.getRevisions().isEmpty(); boolean canAddToEPortfolio = FolderConfig.isEPortfolioAddEnabled(); VFSLeaf leaf = null; if (child instanceof VFSLeaf) { leaf = (VFSLeaf) child; } boolean isContainer = (leaf == null); // if not a leaf, it must be a container... MetaInfo metaInfo = null; if (child instanceof OlatRelPathImpl) { metaInfo = MetaInfoFactory.createMetaInfoFor((OlatRelPathImpl) child); } boolean lockedForUser = MetaInfoHelper.isLocked(metaInfo, fc.getIdentityEnvironnement()); String name = child.getName(); String pathAndName = currentContainerPath; if (pathAndName.length() > 0 && !pathAndName.endsWith("/")) pathAndName = pathAndName + "/"; pathAndName = pathAndName + name; String type = FolderHelper.extractFileType(child.getName(), translator.getLocale()); // tr begin, set alternating bgcolor sb.append("<tr"); bgFlag = !bgFlag; if (bgFlag) { sb.append(" class=\"b_table_odd\""); } sb.append("><td class=\"b_first_child\">"); // add checkbox for actions if user can write or delete to this directory if (canWrite || canDelete) { sb.append("<input type=\"checkbox\" class=\"b_checkbox\" name=\""); sb.append(FileSelection.FORM_ID); sb.append("\" value=\""); sb.append(StringEscapeUtils.escapeHtml(name)); sb.append("\" />"); } // browse link pre sb.append("<a href=\""); if (isContainer) { // for directories... normal module URIs ubu.buildURI(sb, null, null, pathAndName, iframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL); sb.append("\""); if (iframePostEnabled) { // add ajax iframe target StringOutput so = new StringOutput(); ubu.appendTarget(so); sb.append(so.toString()); } } else { // for files, add PARAM_SERV command ubu.buildURI(sb, new String[] { PARAM_SERV }, new String[] { "x" }, pathAndName, AJAXFlags.MODE_NORMAL); sb.append("\" target=\"_blank\""); } // icon css sb.append(" class=\"b_with_small_icon_left "); if (isContainer) sb.append(CSSHelper.CSS_CLASS_FILETYPE_FOLDER); else sb.append(CSSHelper.createFiletypeIconCssClassFor(name)); sb.append("\""); // file metadata if (metaInfo != null) { sb.append(" ext:qtip=\"<div class='b_ext_tooltip_wrapper b_briefcase_meta'>"); if (StringHelper.containsNonWhitespace(metaInfo.getTitle())) { sb.append("<h5>").append(Formatter.escapeDoubleQuotes(metaInfo.getTitle())).append("</h5>"); } if (StringHelper.containsNonWhitespace(metaInfo.getComment())) { sb.append(Formatter.escapeDoubleQuotes(metaInfo.getComment())); } if (metaInfo.isThumbnailAvailable()) { sb.append( "<div class='b_briefcase_preview' style='width:200px; height:200px; background-image:url("); ubu.buildURI(sb, new String[] { PARAM_SERV_THUMBNAIL }, new String[] { "x" }, pathAndName, AJAXFlags.MODE_NORMAL); sb.append("); background-repeat:no-repeat; background-position:50% 50%;'> </div>"); } String author = metaInfo.getAuthor(); if (StringHelper.containsNonWhitespace(author)) { sb.append("<p>").append(Formatter.escapeDoubleQuotes(translator.translate("mf.author"))); sb.append(": ").append(Formatter.escapeDoubleQuotes(author)).append("</p>"); } sb.append("</div>\""); } sb.append(">"); // name if (isAbstract) sb.append("<i>"); sb.append(name); if (isAbstract) sb.append("</i>"); sb.append("</a></td><td>"); // filesize if (!isContainer) { // append filesize sb.append(StringHelper.formatMemory(leaf.getSize())); } sb.append("</td><td>"); // type if (isContainer) { sb.append(translator.translate("Directory")); } else { if (type.equals(TYPE_FILE)) { sb.append(translator.translate("UnknownFile")); } else { sb.append(type.toUpperCase()); sb.append(" ").append(translator.translate(TYPE_FILE)); } } sb.append("</td><td>"); if (canContainerVersion) { if (canVersion) sb.append(versions.getRevisionNr()); sb.append("</td><td>"); } // last modified long lastModified = child.getLastModified(); if (lastModified != VFSConstants.UNDEFINED) sb.append(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, translator.getLocale()) .format(new Date(lastModified))); else sb.append("-"); sb.append("</td><td>"); // locked if (metaInfo != null) { if (metaInfo.isLocked()) { Identity lockedBy = identityMap.get(metaInfo.getLockedBy()); if (lockedBy == null) { lockedBy = metaInfo.getLockedByIdentity(); if (lockedBy != null) { identityMap.put(lockedBy.getKey(), lockedBy); } } sb.append("<span class=\"b_small_icon b_briefcase_locked_file_icon\" ext:qtip=\""); if (lockedBy != null) { String firstName = lockedBy.getUser().getProperty(UserConstants.FIRSTNAME, translator.getLocale()); String lastName = lockedBy.getUser().getProperty(UserConstants.LASTNAME, translator.getLocale()); String date = ""; if (metaInfo.getLockedDate() != null) { date = fc.getDateTimeFormat().format(metaInfo.getLockedDate()); } sb.append(translator.translate("Locked", new String[] { firstName, lastName, date })); } sb.append("\"> </span>"); } } sb.append("</td><td class=\"b_last_child\">"); // Info link if (canWrite) { String nameLowerCase = name.toLowerCase(); if (!lockedForUser && (nameLowerCase.endsWith(".html") || nameLowerCase.endsWith(".htm") || nameLowerCase.endsWith(".txt") || nameLowerCase.endsWith(".css"))) { sb.append("<a href=\""); ubu.buildURI(sb, new String[] { PARAM_CONTENTEDITID }, new String[] { Integer.toString(pos) }, iframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL); sb.append("\""); if (iframePostEnabled) { // add ajax iframe target StringOutput so = new StringOutput(); ubu.appendTarget(so); sb.append(so.toString()); } sb.append(" ext:qtip=\"").append(StringEscapeUtils.escapeHtml(translator.translate("editor"))); sb.append("\" class=\"b_small_icon b_briefcase_edit_file_icon\"></a>"); } boolean canMetaData = MetaInfoHelper.canMetaInfo(child); if (canMetaData) { if (lockedForUser) { // Metadata link disabled... sb.append("<span ext:qtip=\"") .append(StringEscapeUtils.escapeHtml(translator.translate("edit"))) .append("\" class=\" b_small_icon b_briefcase_edit_meta_dis_icon\"> </span>"); } else { // Metadata edit link... also handles rename for non-OlatRelPathImpls sb.append("<a href=\""); ubu.buildURI(sb, new String[] { PARAM_EDTID }, new String[] { Integer.toString(pos) }, iframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL); sb.append("\""); if (iframePostEnabled) { // add ajax iframe target StringOutput so = new StringOutput(); ubu.appendTarget(so); sb.append(so.toString()); } sb.append(" ext:qtip=\"").append(StringEscapeUtils.escapeHtml(translator.translate("mf.edit"))) .append("\" class=\" b_small_icon b_briefcase_edit_meta_icon\"></a>"); } } // get a link for adding a file to ePortfolio, if file-owner is the current user if (canAddToEPortfolio && !isContainer) { if (metaInfo != null) { Identity author = metaInfo.getAuthorIdentity(); if (author != null && fc.getIdentityEnvironnement().getIdentity().getKey().equals(author.getKey())) { sb.append("<a href=\""); ubu.buildURI(sb, new String[] { PARAM_EPORT }, new String[] { Integer.toString(pos) }, iframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL); sb.append("\""); if (iframePostEnabled) { // add ajax iframe target StringOutput so = new StringOutput(); ubu.appendTarget(so); sb.append(so.toString()); } sb.append(" ext:qtip=\"") .append(StringEscapeUtils.escapeHtml(translator.translate("eportfolio"))) .append("\" class=\" b_small_icon b_eportfolio_add\"></a>"); } } } if (canVersion) { // Versions link if (lockedForUser) { sb.append("<span ext:qtip=\"") .append(StringEscapeUtils.escapeHtml(translator.translate("versions"))) .append("\" class=\" b_small_icon b_briefcase_versions_dis_icon\"> </span>"); } else { sb.append("<a href=\""); ubu.buildURI(sb, new String[] { PARAM_VERID }, new String[] { Integer.toString(pos) }, iframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL); sb.append("\""); if (iframePostEnabled) { // add ajax iframe target StringOutput so = new StringOutput(); ubu.appendTarget(so); sb.append(so.toString()); } sb.append(" ext:qtip=\"").append(StringEscapeUtils.escapeHtml(translator.translate("versions"))) .append("\" class=\" b_small_icon b_briefcase_versions_icon\"></a>"); } } } else { sb.append(" "); } sb.append("</td></tr>"); }
From source file:com.redhat.rhn.common.localization.LocalizationService.java
/** * Format the date based on the locale and convert it to a String to * display. Uses DateFormat.SHORT. Example: 2004-12-10 13:20:00 PST * * Also includes the timezone of the current User if there is one * * @param date Date to format.//from ww w .java2s . co m * @param locale Locale to use for formatting. * @return String representation of given date in given locale. */ public String formatDate(Date date, Locale locale) { // Example: 2004-12-10 13:20:00 PST StringBuilder dbuff = new StringBuilder(); DateFormat dateI = DateFormat.getDateInstance(DateFormat.SHORT, locale); dateI.setTimeZone(determineTimeZone()); DateFormat timeI = DateFormat.getTimeInstance(DateFormat.LONG, locale); timeI.setTimeZone(determineTimeZone()); dbuff.append(dateI.format(date)); dbuff.append(" "); dbuff.append(timeI.format(date)); return getDebugVersionOfString(dbuff.toString()); }
From source file:org.svij.taskwarriorapp.activities.TaskAddActivity.java
@Override public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) { cal.set(Calendar.HOUR_OF_DAY, hourOfDay); cal.set(Calendar.MINUTE, minute); cal.set(Calendar.SECOND, 0);// ww w . j a v a 2s . co m timestamp = cal.getTimeInMillis(); TextView etTaskTime = (TextView) findViewById(R.id.tvDueTime); etTaskTime.setText(DateFormat.getTimeInstance(DateFormat.SHORT).format(timestamp)); TextView etTaskDate = (TextView) findViewById(R.id.tvDueDate); etTaskDate.setText(DateFormat.getDateInstance(DateFormat.SHORT).format(timestamp)); }
From source file:org.sakaiproject.tool.section.jsf.backingbean.RosterBean.java
protected String getDownloadFileName(String rawString) { String dateString = DateFormat.getDateInstance(DateFormat.SHORT).format(new Date()); return (rawString + "_" + dateString).replaceAll("[\\W&&[^\\u0080-\\uffff]]", "_"); }
From source file:desmoj.extensions.grafic.util.Plotter.java
/** * configure domainAxis (label, timeZone, locale, tick labels) * of time-series chart/*from w w w . j ava 2 s . c o m*/ * @param dateAxis */ private void configureDomainAxis(DateAxis dateAxis) { if (this.begin != null) dateAxis.setMinimumDate(this.begin); if (this.end != null) dateAxis.setMaximumDate(this.end); dateAxis.setTimeZone(this.timeZone); Date dateMin = dateAxis.getMinimumDate(); Date dateMax = dateAxis.getMaximumDate(); //DateFormat formatter = new SimpleDateFormat("d.MM.yyyy HH:mm:ss.SSS");; DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM, locale); String label = "Time: " + formatter.format(dateMin) + " .. " + formatter.format(dateMax); formatter = new SimpleDateFormat("z"); label += " " + formatter.format(dateMax); dateAxis.setLabel(label); TimeInstant max = new TimeInstant(dateMax); TimeInstant min = new TimeInstant(dateMin); TimeSpan diff = TimeOperations.diff(max, min); if (TimeSpan.isLongerOrEqual(diff, new TimeSpan(1, TimeUnit.DAYS))) formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale); else if (TimeSpan.isLongerOrEqual(diff, new TimeSpan(1, TimeUnit.HOURS))) formatter = DateFormat.getTimeInstance(DateFormat.SHORT, locale); else if (TimeSpan.isLongerOrEqual(diff, new TimeSpan(1, TimeUnit.MINUTES))) formatter = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale); else formatter = new SimpleDateFormat("HH:mm:ss.SSS"); dateAxis.setDateFormatOverride(formatter); dateAxis.setVerticalTickLabels(true); }
From source file:org.sakaiproject.assignment2.logic.impl.ExternalLogicImpl.java
public DateFormat getDateFormat(Integer optionalDateStyle, Integer optionalTimeStyle, Locale locale, boolean currentUserTimezone) { int dateStyle = optionalDateStyle != null ? optionalDateStyle : DateFormat.MEDIUM; int timeStyle = optionalTimeStyle != null ? optionalTimeStyle : DateFormat.SHORT; DateFormat df = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale); if (currentUserTimezone) { df.setTimeZone(timeService.getLocalTimeZone()); }/*from www . j a v a 2 s . com*/ return df; }
From source file:it.attocchi.jsf2.PageBase.java
public String getCurrentLocaleDatePattern() { SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, getCurrentLocale());// w ww . j a va 2s. c om return format.toLocalizedPattern(); }