List of usage examples for java.text DateFormat getDateTimeInstance
public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle)
From source file:com.google.ie.common.audit.AuditManager.java
/** * Add the task to a {@link Queue} to audit the user action. * /*from w ww .j av a2s .c o m*/ * @param userKey the key of the user whose action is to be audited * @param entityKey the key of the entity on which the action was performed * @param action the action performed */ public void audit(String userKey, String entityKey, String entityType, String action) { /* Use Task Queue to queue the task to audit. */ Queue queue = QueueFactory.getQueue(IdeaExchangeConstants.TASK_QUEUE); TaskOptions taskOptions = TaskOptions.Builder.url(IdeaExchangeConstants.AUDIT_URL) .param(IdeaExchangeConstants.USER_KEY, userKey).param(IdeaExchangeConstants.ENTITY_KEY, entityKey) .param(IdeaExchangeConstants.ENTITY_TYPE, entityType) .param(IdeaExchangeConstants.AUDIT_DATE, DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(new Date())) .param(IdeaExchangeConstants.ACTION, action); queue.add(taskOptions); if (log.isDebugEnabled()) { log.debug("Task for auditing added to queue :" + IdeaExchangeConstants.TASK_QUEUE); } }
From source file:org.apache.hadoop.security.token.DtFileOperations.java
/** Format a long integer type into a date string. */ private static String formatDate(long date) { DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); return df.format(new Date(date)); }
From source file:org.kalypso.utils.log.FileLog.java
/** * The constructor.//from w w w .j ava2 s. co m * * @param file * The log file. May not be null. */ public FileLog(final File file) { /* The log file may not be null. */ Assert.isNotNull(file); m_file = file; m_df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT); }
From source file:org.rhq.modules.plugins.jbossas7.util.PatchDetails.java
public static List<PatchDetails> fromHistory(String patchHistoryOutcome) { ObjectMapper mapper = new ObjectMapper(); Result result;/*w w w. j a va2s . c o m*/ try { result = mapper.readValue(patchHistoryOutcome, Result.class); } catch (IOException e) { LOG.warn("Failed to parse the output of the 'patch history' command with message '" + e.getMessage() + "'. The output was:\n" + patchHistoryOutcome); return Collections.emptyList(); } if (!result.isSuccess()) { if (LOG.isDebugEnabled()) { LOG.debug("'patch history' command didn't succeed: " + result); } return Collections.emptyList(); } // expecting a list of maps of string->string if (!(result.getResult() instanceof List)) { if (LOG.isDebugEnabled()) { LOG.debug("Unexpected patch history results. Expected list but found " + (result.getResult() == null ? "null" : result.getResult().getClass().toString())); } return Collections.emptyList(); } @SuppressWarnings("unchecked") List<Map<String, String>> patches = (List<Map<String, String>>) result.getResult(); if (patches.isEmpty()) { return Collections.emptyList(); } List<PatchDetails> ret = new ArrayList<PatchDetails>(); for (Map<String, String> patchDescr : patches) { String patchId = patchDescr.get("patch-id"); Date appliedAt = null; Type type = Type.fromJsonValue(patchDescr.get("type")); try { //This seems to be the date format AS are using DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); appliedAt = format.parse(patchDescr.get("applied-at")); } catch (ParseException e) { LOG.info("Failed to parse the installation date of the patch " + patchId + ": '" + patchDescr.get("applied-at") + "' with error message: " + e.getMessage()); } ret.add(new PatchDetails(patchId, type, appliedAt)); } return ret; }
From source file:org.hyperic.hq.measurement.server.session.ReportStatsCollector.java
@Autowired public ReportStatsCollector(DiagnosticsLogger diagnosticsLogger, ServerConfigManager serverConfigManager) { diagnosticsLogger.addDiagnosticObject(new DiagnosticObject() { public String getName() { return "Metric Reports Stats"; }//from w w w . j a v a 2s.co m public String getShortName() { return "metricReportsStats"; } public String toString() { return "ReportStatsCollector"; } public String getStatus() { DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG); long start = getCollector().getOldestTime(); long end = getCollector().getNewestTime(); long now = System.currentTimeMillis(); double nMetrics = getCollector().valPerTimestamp(now) * 60; PrintfFormat pfmt = new PrintfFormat("%.3f"); return "Metric Report Data\n" + " Start: " + fmt.format(new Date(start)) + "\n" + " End: " + fmt.format(new Date(end)) + "\n" + " Samples: " + getCollector().getSize() + "\n" + " Rate: " + pfmt.sprintf(nMetrics) + " kMetrics / min"; } public String getShortStatus() { return getStatus(); } }); this.serverConfigManager = serverConfigManager; }
From source file:org.ez18n.apt.processor.BundlePropertiesProcessor.java
protected final String getProperty(TypeElement bundleType, LabelTemplateMethod method) { try {/*from w ww. jav a2 s . c o m*/ final Map<String, String> conf = new HashMap<String, String>(); conf.put("process.class", getClass().getName()); conf.put("process.date", DateFormat.getDateTimeInstance(SHORT, SHORT).format(new Date())); conf.put("key", method.getName()); conf.put("value", toAscii(getPropertyValue(method))); return replaceProperties(template, conf, NO_VALUE); } catch (PropertyParsingException e) { throw new RuntimeException(e); } }
From source file:com.jaeksoft.searchlib.ClientCatalogItem.java
public String getLastModifiedString() { Date dt = getLastModifiedDate(); if (dt == null) return null; return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(dt); }
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 w w . ja v a 2 s. co m 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.apache.jcs.admin.JCSAdminBean.java
/** * Builds up info about each element in a region. * <p>/*w ww .java 2 s . co m*/ * @param cacheName * @return List of CacheElementInfo objects * @throws Exception */ public LinkedList buildElementInfo(String cacheName) throws Exception { CompositeCache cache = cacheHub.getCache(cacheName); Object[] keys = cache.getMemoryCache().getKeyArray(); // Attempt to sort keys according to their natural ordering. If that // fails, get the key array again and continue unsorted. try { Arrays.sort(keys); } catch (Exception e) { keys = cache.getMemoryCache().getKeyArray(); } LinkedList records = new LinkedList(); ICacheElement element; IElementAttributes attributes; CacheElementInfo elementInfo; DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); long now = System.currentTimeMillis(); for (int i = 0; i < keys.length; i++) { element = cache.getMemoryCache().getQuiet((Serializable) keys[i]); attributes = element.getElementAttributes(); elementInfo = new CacheElementInfo(); elementInfo.key = String.valueOf(keys[i]); elementInfo.eternal = attributes.getIsEternal(); elementInfo.maxLifeSeconds = attributes.getMaxLifeSeconds(); elementInfo.createTime = format.format(new Date(attributes.getCreateTime())); elementInfo.expiresInSeconds = (now - attributes.getCreateTime() - (attributes.getMaxLifeSeconds() * 1000)) / -1000; records.add(elementInfo); } return records; }
From source file:org.eclipse.mylyn.internal.reviews.ui.editors.parts.AbstractCommentPart.java
@Override protected String getSectionHeaderText() { IUser author = comment.getAuthor();// ww w. ja v a2 s. com return NLS.bind(Messages.AbstractCommentPart_Section_header, // author != null ? author.getDisplayName() : Messages.AbstractCommentPart_No_author, // DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT) .format(comment.getCreationDate()) // ); }