List of usage examples for java.text DateFormat getDateTimeInstance
public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle)
From source file:org.ez18n.apt.processor.DesktopMessagesProcessor.java
@Override protected String getCode(TypeElement bundleType, List<LabelTemplateMethod> methods) { final StringBuffer methodsCode = new StringBuffer(); for (LabelTemplateMethod method : methods) { methodsCode.append(getCode(bundleType, method)); }// ww w . ja v a 2s .c om final String code; 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("target.class.name", getTargetSimpleName(bundleType)); conf.put("source.class.name", bundleType.getSimpleName().toString()); conf.put("package.name", bundleType.getEnclosingElement().toString()); conf.put("methods.code", methodsCode.toString()); try { code = replaceProperties(template, conf, NO_VALUE); } catch (PropertyParsingException e) { throw new RuntimeException(e); } return code; }
From source file:com.google.ie.web.controller.AuditController.java
/** * Register custom binders for Spring. Needed to run on app engine * //w w w .j a va 2s . c om * @param binder * @param request */ @InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(Boolean.class, new CustomBooleanEditor(true)); binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); binder.registerCustomEditor(Date.class, new CustomDateEditor(DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL), true)); }
From source file:org.rhq.modules.plugins.wildfly10.util.PatchDetails.java
private static PatchDetails processJSONParseResult(Map<String, String> jsonParseResult) { String patchId = jsonParseResult.get("patch-id"); Date appliedAt = null;/*from www . ja v a 2 s . co m*/ Type type = Type.fromJsonValue(jsonParseResult.get("type")); try { //This seems to be the date format AS are using DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); appliedAt = format.parse(jsonParseResult.get("applied-at")); } catch (ParseException e) { LOG.info("Failed to parse the installation date of the patch " + patchId + ": '" + jsonParseResult.get("applied-at") + "' with error message: " + e.getMessage()); } return new PatchDetails(patchId, type, appliedAt); }
From source file:com.microsoft.tfs.client.common.ui.controls.vc.LabelItemTable.java
@Override protected String getColumnText(final Object element, final String propertyName) { final LabelItem item = (LabelItem) element; if (propertyName.equals(ITEM_COLUMN_ID)) { return VersionedFileSpec.formatPathWithDeletionIfNecessary(item.getServerItem(), item.getDeletionID()); } else if (propertyName.equals(VERSION_COLUMN_ID)) { final VersionSpec versionSpec = item.getVersionSpec(); if (versionSpec instanceof LatestVersionSpec) { return Messages.getString("LabelItemTable.ColumnTextLatest"); //$NON-NLS-1$ } else if (versionSpec instanceof LabelVersionSpec) { final LabelVersionSpec labelSpec = (LabelVersionSpec) versionSpec; return labelSpec.getLabel() + "@" + labelSpec.getScope(); //$NON-NLS-1$ } else if (versionSpec instanceof DateVersionSpec) { final Date date = ((DateVersionSpec) versionSpec).getDate().getTime(); return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date); } else if (versionSpec instanceof WorkspaceVersionSpec) { final WorkspaceVersionSpec workspaceSpec = (WorkspaceVersionSpec) versionSpec; return workspaceSpec.getName() + ";" + workspaceSpec.getOwner(); //$NON-NLS-1$ } else if (versionSpec instanceof ChangesetVersionSpec) { return Integer.toString(((ChangesetVersionSpec) versionSpec).getChangeset()); } else {/*from w w w. j a va 2 s . c o m*/ return versionSpec.toString(); } } return "(Unknown)"; //$NON-NLS-1$ }
From source file:com.glanznig.beepme.view.ViewSampleFragment.java
private void populateFields() { if (sampleId != 0L) { Sample s = new SampleTable(getActivity().getApplicationContext()).getSampleWithTags(sampleId); TextView timestamp = (TextView) getView().findViewById(R.id.view_sample_timestamp); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); timestamp.setText(dateFormat.format(s.getTimestamp())); TextView title = (TextView) getView().findViewById(R.id.view_sample_title); if (s.getTitle() != null && s.getTitle().length() > 0) { title.setText(s.getTitle()); } else {/*www.j av a2 s . c o m*/ title.setText(getString(R.string.sample_untitled)); } TextView description = (TextView) getView().findViewById(R.id.view_sample_description); if (s.getDescription() != null && s.getDescription().length() > 0) { description.setTextSize(14); description.setText(s.getDescription()); } else { description.setTextSize(12); // not editable any more if ((Calendar.getInstance().getTimeInMillis() - s.getTimestamp().getTime()) >= 24 * 60 * 60 * 1000) { description.setText(getString(R.string.sample_no_description)); } else { description.setText(getString(R.string.sample_no_description_editable)); } } boolean hasKeywordTags = false; FlowLayout keywordHolder = (FlowLayout) getView().findViewById(R.id.view_sample_keyword_container); keywordHolder.removeAllViews(); Iterator<Tag> i = s.getTags().iterator(); Tag tag = null; while (i.hasNext()) { tag = i.next(); if (tag.getVocabularyId() == 1) { TextView view = new TextView(getView().getContext()); view.setText(tag.getName()); final float scale = getResources().getDisplayMetrics().density; int textPaddingLeftRight = 6; int textPaddingTopBottom = 2; view.setPadding((int) (textPaddingLeftRight * scale + 0.5f), (int) (textPaddingTopBottom * scale + 0.5f), (int) (textPaddingLeftRight * scale + 0.5f), (int) (textPaddingTopBottom * scale + 0.5f)); view.setBackgroundColor(getResources().getColor(R.color.bg_keyword)); keywordHolder.addView(view); hasKeywordTags = true; } } TextView noKeywordsView = (TextView) getView().findViewById(R.id.view_sample_no_keywords); if (!hasKeywordTags) { keywordHolder.setVisibility(View.GONE); noKeywordsView.setVisibility(View.VISIBLE); // not editable any more (after 1 day) if ((Calendar.getInstance().getTimeInMillis() - s.getTimestamp().getTime()) >= 24 * 60 * 60 * 1000) { noKeywordsView.setText(getString(R.string.sample_no_keywords)); } else { noKeywordsView.setText(getString(R.string.sample_no_keywords_editable)); } } else { noKeywordsView.setVisibility(View.GONE); keywordHolder.setVisibility(View.VISIBLE); } photoView = (SamplePhotoView) getView().findViewById(R.id.view_sample_photo); photoView.setRights(false, false); // read only DisplayMetrics metrics = getView().getContext().getResources().getDisplayMetrics(); int thumbnailSize; if (!isLandscape()) { photoView.setFrameWidth(LayoutParams.MATCH_PARENT); thumbnailSize = (int) (metrics.widthPixels / metrics.density + 0.5f); } else { thumbnailSize = (int) (metrics.heightPixels / metrics.density + 0.5f); } String thumbnailUri = PhotoUtils.getThumbnailUri(s.getPhotoUri(), thumbnailSize); if (thumbnailUri != null) { File thumb = new File(thumbnailUri); if (thumb.exists()) { ImgLoadHandler handler = new ImgLoadHandler(photoView); PhotoUtils.getAsyncBitmap(getView().getContext(), thumbnailUri, handler); } else { Handler handler = new Handler(this); PhotoUtils.generateThumbnails(getView().getContext(), s.getPhotoUri(), handler); } } else { photoView.unsetPhoto(); } } }
From source file:de.taimos.gpsd4java.backend.AbstractResultParser.java
protected double parseTimestamp(final JSONObject json, final String fieldName) { try {//from w w w. j av a2 s . c o m final String text = json.optString(fieldName, null); AbstractResultParser.LOG.debug(fieldName + ": {}", text); if (text != null) { final Date date = this.dateFormat.parse(text); if (AbstractResultParser.LOG.isDebugEnabled()) { final String ds = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(date); AbstractResultParser.LOG.debug("Date: {}", ds); } return date.getTime() / 1000.0; } } catch (final Exception ex) { AbstractResultParser.LOG.info("Failed to parse time", ex); } return Double.NaN; }
From source file:com.zimbra.cs.service.util.ItemDataFile.java
public static void list(InputStream is, Set<MailItem.Type> types, String cset, PrintStream os) throws IOException { DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); TarEntry te;/* www . j a v a2 s.co m*/ TarInputStream tis = new TarInputStream(new GZIPInputStream(is), cset == null ? "UTF-8" : cset); os.format("%-13s %17s %10s %6s %s\n", "TYPE", "DATE", "SIZE", "METASZ", "PATH"); try { TarEntry idEntry = null; while ((te = tis.getNextEntry()) != null) { if (te.getName().endsWith(".meta")) { if (idEntry != null && !skip(types, MailItem.Type.of((byte) idEntry.getMajorDeviceId()))) { os.format("%-13s %17s %10s %6d %s\n", idEntry.getGroupName(), df.format(idEntry.getModTime()), 0, idEntry.getSize(), idEntry.getName().substring(0, idEntry.getName().indexOf(".meta"))); } idEntry = te; } else { if (!skip(types, MailItem.Type.of((byte) te.getMajorDeviceId()))) { os.format("%-13s %17s %10s %6d %s\n", te.getGroupName(), df.format(te.getModTime()), te.getSize(), idEntry == null ? 0 : idEntry.getSize(), te.getName()); } idEntry = null; } } if (idEntry != null && !skip(types, MailItem.Type.of((byte) idEntry.getMajorDeviceId()))) { os.format("%-13s %17s %10s %6d %s\n", idEntry.getGroupName(), df.format(idEntry.getModTime()), 0, idEntry.getSize(), idEntry.getName().substring(0, idEntry.getName().indexOf(".meta"))); } } finally { tis.close(); } }
From source file:am.project.x.business.widgets.zxingscanview.ZxingScanViewActivity.java
@Override public void onResult(ZxingScanView scanView, Result result, Bitmap barcode, float scaleFactor) { ParsedResult parsedResult = ResultParser.parseResult(result); final String format = "format:" + result.getBarcodeFormat().toString(); final String type = "type:" + parsedResult.getType().toString(); DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); final String date = "date:" + formatter.format(new Date(result.getTimestamp())); String meta = ""; Map<ResultMetadataType, Object> metadata = result.getResultMetadata(); if (metadata != null) { StringBuilder metadataText = new StringBuilder(20); for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) { if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) { metadataText.append(entry.getValue()).append('\n'); }/* w ww. java 2 s .c o m*/ } if (metadataText.length() > 0) { metadataText.setLength(metadataText.length() - 1); meta = metadataText.toString(); } } CharSequence displayContents = parsedResult.getDisplayResult(); Toast.makeText(this, format + "\n" + type + "\n" + date + "\n" + meta + "\n" + displayContents, Toast.LENGTH_SHORT).show(); // ??? scanView.restartScanDelay(3000); }
From source file:de.jcup.egradle.eclipse.ide.execution.EclipseLaunchProcessExecutor.java
@Override protected void handleProcessStarted(EnvironmentProvider provider, Process process, Date started, File workingDirectory, String[] commands) { String label = "<none>"; if (provider instanceof GradleContext) { label = ((GradleContext) provider).getCommandString(); }/*from ww w . j av a 2 s .c o m*/ String path = "inside root project"; Map<String, String> attributes = new HashMap<>(); String timestamp = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(started); /* * Will be shown in process information dialog - see * org.eclipse.debug.internal.ui.preferences. ProcessPropertyPage */ StringBuilder sb = new StringBuilder(); for (String key : provider.getEnvironment().keySet()) { String value = provider.getEnvironment().get(key); sb.append(key); sb.append('='); sb.append(value); sb.append(System.getProperty("line.separator")); } attributes.put(DebugPlugin.ATTR_ENVIRONMENT, sb.toString()); attributes.put(DebugPlugin.ATTR_CONSOLE_ENCODING, "UTF-8"); attributes.put(DebugPlugin.ATTR_WORKING_DIRECTORY, workingDirectory.getAbsolutePath()); attributes.put(DebugPlugin.ATTR_LAUNCH_TIMESTAMP, timestamp); attributes.put(DebugPlugin.ATTR_PATH, path); /* * using an unbreakable space 00A0 to avoid unnecessary breaks in view */ cmdLine = StringUtils.join(Arrays.asList(commands), '\u00A0'); attributes.put(IProcess.ATTR_CMDLINE, cmdLine); /* * bind process to runtime process, so visible and correct handled in * debug UI */ EGradleRuntimeProcess rp = EGradleRuntimeProcess.create(launch, process, label, attributes); // rp.getStreamsProxy().getOutputStreamMonitor().addListener(rp); outputHandler.output("Launch started - for details see output of " + label); if (!rp.canTerminate()) { outputHandler.output("Started process cannot terminate"); } }
From source file:org.apache.sqoop.shell.ShowLinkFunction.java
private void displayLink(MLink link) { DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); printlnResource(Constants.RES_SHOW_PROMPT_LINK_INFO, link.getPersistenceId(), link.getName(), link.getEnabled(), link.getCreationUser(), formatter.format(link.getCreationDate()), link.getLastUpdateUser(), formatter.format(link.getLastUpdateDate())); long connectorId = link.getConnectorId(); printlnResource(Constants.RES_SHOW_PROMPT_LINK_CID_INFO, connectorId); // Display link config displayConfig(link.getConnectorLinkConfig().getConfigs(), client.getConnectorConfigBundle(connectorId)); }