List of usage examples for java.text DateFormat getDateTimeInstance
public static final DateFormat getDateTimeInstance()
From source file:org.eclipse.swordfish.samples.configuration.ConfigurationProvider.java
public void afterPropertiesSet() throws Exception { Assert.notNull(id);//from w w w .j a v a 2s .com final Map<String, Object> configData = new HashMap<String, Object>(); configData.put("testProperty1", "Updated by ConfigurationProvider"); configData.put("currentDateTime", DateFormat.getDateTimeInstance().format(new Date())); LOG.info("Updating configuration"); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { swordfishContext.getConfigurationService().updateConfiguration(id, configData); } }, 5000); }
From source file:com.twinsoft.convertigo.engine.util.CookiesUtils.java
public static void addCookie(HttpState httpState, String cook) { String name = ""; String domain = ""; String path = ""; String value = ""; boolean secure = false; Date expires = new Date(Long.MAX_VALUE); String[] fields = cook.split(";"); for (int i = 0; i < fields.length; i++) { String[] half = fields[i].trim().split("="); if (half.length == 2) { if (fields[i].startsWith("$")) { if (half[0].equals("$Domain")) domain = half[1];//from ww w . j a v a 2 s .c o m else if (half[0].equals("$Path")) path = half[1]; else if (half[0].equals("$Secure")) secure = Boolean.getBoolean(half[1]); else if (half[0].equals("$Date")) try { expires = DateFormat.getDateTimeInstance().parse(half[1]); } catch (ParseException e) { } } else { name = half[0]; value = half[1]; } } } Cookie cookie = null; try { cookie = new Cookie(domain, name, value, path, expires, secure); if (cookie != null) httpState.addCookie(cookie); } catch (Exception e) { Engine.logBeans.debug("(CookiesUtils) failed to parse cookie: " + cook); } }
From source file:org.adaptto.rookie.demo.components.DiscussionComment.java
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { Writer out = response.getWriter(); // read comment via Sling Model Comment comment = request.getResource().adaptTo(Comment.class); // output comment as HTML out.write("<p>"); out.write("<em>" + escapeHtml(comment.getAuthor()) + " (" + DateFormat.getDateTimeInstance().format(comment.getCreated()) + ")</em><br/>"); out.write(escapeHtml(comment.getText())); out.write("</p>"); }
From source file:com.acuityph.commons.logging.SimpleFormatter.java
/** * {@inheritDoc}//from w ww.j a va2s . co m * * @see java.util.logging.Formatter#format(java.util.logging.LogRecord) */ @Override public final String format(final LogRecord logRecord) { final StringBuilder sb = new StringBuilder(); sb.append(LEVELS_MAP.get(logRecord.getLevel())); final DateFormat sdf = DateFormat.getDateTimeInstance(); sb.append(sdf.format(new Date(logRecord.getMillis()))).append(' '); sb.append(getShortName(logRecord.getSourceClassName())); sb.append('.').append(logRecord.getSourceMethodName()).append(": "); sb.append(logRecord.getMessage()).append("\n"); return sb.toString(); }
From source file:gridrover.CommandlineRoverControl.java
/** * Get a command from the user and return it * * @return A Command object//from w w w . j a va 2 s . co m */ public Command getNextCommand(Calendar now) { Command command = null; while (command == null) { System.out.print(DateFormat.getDateTimeInstance().format(now.getTime()) + "> "); // Scotty, prompt me up //TODO: Consolidate console user input code String inputLine = null; try { inputLine = reader.readLine(); } catch (IOException ioe) { System.err.println("IO error trying to read from System.in"); System.exit(1); } String[] words = inputLine.split(" "); String[] args = new String[words.length - 1]; System.arraycopy(words, 1, args, 0, args.length); for (CommandWord w : CommandWord.values()) { if (words[0].equalsIgnoreCase(w.toString())) command = new Command(w, args); } if (command == null) System.out.println("Unrecognized command: " + words[0]); } return command; }
From source file:com.adobe.acs.commons.version.impl.EvolutionConfig.java
public static String printObject(Object obj) { if (obj == null) { return ""; }//from w w w . ja v a2 s . c om if (obj instanceof String) { return (String) obj; } else if (obj instanceof String[]) { String[] values = (String[]) obj; StringBuilder result = new StringBuilder(); result.append("["); for (int i = 0; i < values.length; i++) { result.append(values[i]); if (i != (values.length - 1)) { result.append(", "); } } result.append("]"); return result.toString(); } else if (obj instanceof Calendar) { Calendar value = (Calendar) obj; DateFormat dateFormat = DateFormat.getDateTimeInstance(); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); return dateFormat.format(value.getTime()); } else { return obj.toString(); } }
From source file:org.openmrs.module.emrmonitor.metric.JavaRuntimeMetricProducer.java
/** * @return a list of produced metrics//from w ww .j a v a2 s . co m */ @Override public Map<String, String> produceMetrics() { Map<String, String> metrics = new LinkedHashMap<String, String>(); // Memory Runtime runtime = Runtime.getRuntime(); metrics.put("memory.total", FormatUtil.formatBytes(runtime.totalMemory())); metrics.put("memory.total.bytes", Long.toString(runtime.totalMemory())); metrics.put("memory.free", FormatUtil.formatBytes(runtime.freeMemory())); metrics.put("memory.free.bytes", Long.toString(runtime.freeMemory())); metrics.put("memory.maximum", FormatUtil.formatBytes(runtime.maxMemory())); metrics.put("memory.maximum.bytes", Long.toString(runtime.maxMemory())); // Date/time Calendar cal = Calendar.getInstance(); metrics.put("datetime.display", DateFormat.getDateTimeInstance().format(cal.getTime())); metrics.put("datetime.date", DateFormatUtils.ISO_DATE_FORMAT.format(cal)); metrics.put("datetime.time", DateFormatUtils.ISO_TIME_NO_T_FORMAT.format(cal)); metrics.put("datetime.timezone", cal.getTimeZone().getDisplayName()); // Java Properties sp = System.getProperties(); metrics.put("version", sp.getProperty("java.version")); metrics.put("vendor", sp.getProperty("java.vendor")); metrics.put("jvmVersion", sp.getProperty("java.vm.version")); metrics.put("jvmVendor", sp.getProperty("java.vm.vendor")); metrics.put("runtimeName", sp.getProperty("java.runtime.name")); metrics.put("runtimeVersion", sp.getProperty("java.runtime.version")); metrics.put("user.name", sp.getProperty("user.name")); metrics.put("user.language", sp.getProperty("user.language")); metrics.put("user.timezone", sp.getProperty("user.timezone")); metrics.put("user.directory", sp.getProperty("user.dir")); metrics.put("encoding", sp.getProperty("sun.jnu.encoding")); metrics.put("tempDirectory", sp.getProperty("java.io.tmpdir")); return metrics; }
From source file:org.psikeds.resolutionengine.transformer.impl.Vo2PojoTransformer.java
@Override public Metadata valueObject2Pojo(final org.psikeds.resolutionengine.datalayer.vo.MetaData vo) { Metadata pojo = null;//from www.j ava 2 s.co m if (vo != null) { pojo = new Metadata(); final Calendar created = (vo.getLastmodified() == null ? vo.getCreated() : vo.getLastmodified()); if (created != null) { pojo.addInfo(Metadata.KB_CREATED, DateFormat.getDateTimeInstance().format(created.getTime())); } if (vo.getLoaded() != null) { pojo.addInfo(Metadata.KB_LOADED, DateFormat.getDateTimeInstance().format(vo.getLoaded().getTime())); } if (!StringUtils.isEmpty(vo.getLanguage())) { pojo.addInfo(Metadata.KB_LANGUAGE, vo.getLanguage()); } if (!StringUtils.isEmpty(vo.getRelease())) { pojo.addInfo(Metadata.KB_VERSION, vo.getRelease()); } if (!StringUtils.isEmpty(vo.getName())) { pojo.addInfo(Metadata.KB_NAME, vo.getName()); } if (!StringUtils.isEmpty(vo.getId())) { pojo.addInfo(Metadata.KB_NAME, vo.getId()); } pojo.addInfo(vo.getAdditionalInfo()); LOGGER.trace("valueObject2Pojo: vo = {}\n--> pojo = {}", vo, pojo); } return pojo; }
From source file:com.google.android.gms.location.sample.backgroundlocationupdates.LocationResultHelper.java
/** * Returns the title for reporting about a list of {@link Location} objects. *///from w ww . ja v a2s. c o m private String getLocationResultTitle() { String numLocationsReported = mContext.getResources().getQuantityString(R.plurals.num_locations_reported, mLocations.size(), mLocations.size()); return numLocationsReported + ": " + DateFormat.getDateTimeInstance().format(new Date()); }
From source file:com.technion.coolie.techpark.ActivityRecognitionIntentService.java
/** * Called when a new activity detection update is available. *//* ww w.j ava 2 s . c om*/ @Override protected void onHandleIntent(Intent intent) { // Get a handle to the repository // TODO: to see if the shared preferences are needed mPrefs = getApplicationContext().getSharedPreferences(ClientSideUtils.SHARED_PREFERENCES, Context.MODE_PRIVATE); // Get a date formatter, and catch errors in the returned timestamp try { mDateFormat = (SimpleDateFormat) DateFormat.getDateTimeInstance(); } catch (Exception e) { Log.e(ClientSideUtils.APPTAG, getString(R.string.date_format_error)); } // Format the timestamp according to the pattern, then localize the pattern mDateFormat.applyPattern(DATE_FORMAT_PATTERN); mDateFormat.applyLocalizedPattern(mDateFormat.toLocalizedPattern()); // If the intent contains an update if (ActivityRecognitionResult.hasResult(intent)) { // Get the update ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent); // Log the update logActivityRecognitionResult(result); // Get the most probable activity from the list of activities in the update DetectedActivity mostProbableActivity = result.getMostProbableActivity(); // Get the type of activity int activityType = mostProbableActivity.getType(); // Check to see if the repository contains a previous activity if (!mPrefs.contains(ClientSideUtils.KEY_PREVIOUS_ACTIVITY_TYPE)) { // This is the first type an activity has been detected. Store the type Editor editor = mPrefs.edit(); editor.putInt(ClientSideUtils.KEY_PREVIOUS_ACTIVITY_TYPE, activityType); editor.commit(); // If the repository contains a type } } }