List of usage examples for java.text DateFormat getDateTimeInstance
public static final DateFormat getDateTimeInstance()
From source file:com.coinblesk.client.utils.UIUtils.java
public static String lockedUntilText(long lockTime) { String lockedUntil;//from w ww . j ava2s . co m if (BitcoinUtils.isLockTimeByTime(lockTime)) { lockedUntil = DateFormat.getDateTimeInstance().format(new Date(lockTime * 1000L)); } else { lockedUntil = String.format(Locale.US, "block %d", lockTime); } return lockedUntil; }
From source file:org.pengyou.client.lib.DavResource.java
/** * Get an array of pathnames and basic information denoting the WebDAV * resources in the denoted by this pathname. * * array 0: displayname/*from w w w . j a v a2s. c o m*/ * array 1: getcontentlength * array 2: iscollection or getcontentype * array 3: getlastmodifieddate * array 4: name * array 5: getcreationdate * array 6: getowner * * @return An array of pathnames and more denoting the resources. * @exception HttpException * @exception IOException */ public Vector listBasic() throws HttpException, IOException { if (defaultDepth != DepthSupport.DEPTH_1 || !propfindExecuted) setAllProp(DepthSupport.DEPTH_1); Enumeration hrefs = childResources.getResourceNames(); Vector hrefList = new Vector(); while (hrefs.hasMoreElements()) { try { String resourceName = (String) hrefs.nextElement(); DavResource currentResource = childResources.getResource(resourceName); String[] longFormat = new String[7]; // displayname. longFormat[0] = currentResource.getDisplayName(); long length = currentResource.getContentLength(); // getcontentlength longFormat[1] = new Long(length).toString(); // resourcetype ResourceTypeProperty resourceTypeProperty = currentResource.getResourceType(); // getcontenttype String getContentType = currentResource.getContentType(); longFormat[2] = resourceTypeProperty.isCollection() ? "COLLECTION" : getContentType; Date date = new Date(currentResource.getLastModified()); // getlastmodified // Save the dummy what if failed. longFormat[3] = (date == null) ? "-- -- ----" : // Print the local fancy date format. DateFormat.getDateTimeInstance().format(date); hrefList.addElement(longFormat); // real name of componente longFormat[4] = currentResource.getName(); date = new Date(currentResource.getCreationDate()); // getlastmodified // Save the dummy what if failed. longFormat[5] = (date == null) ? "-- -- ----" : // Print the local fancy date format. DateFormat.getDateTimeInstance().format(date); longFormat[6] = currentResource.getOwner(); } catch (Exception e) { // FIXME: After if's gotten an exception, any solution log.error(e, e); } } return hrefList; }
From source file:org.pengyou.ooo.OpenDialog.java
private String formatList(String[] t) { String res = new String(); if (t[2] == "COLLECTION") { if (t[4].length() > SPACES_FILE - 4) res = t[4].substring(0, SPACES_FILE - 5) + ""; else//from ww w . j a va2 s . c o m res = t[4]; res = " " + res; } else { if (t[4].length() > SPACES_FILE - 2) res = t[4].substring(0, SPACES_FILE - 3) + ""; else res = t[4]; } while (res.length() < SPACES_FILE) res += " "; res += t[6]; while (res.length() < SPACES_AUTHOR) res += " "; Locale locale = Locale.FRENCH; Date date = null; String s = null; try { date = DateFormat.getDateTimeInstance().parse(t[5]); s = DateFormat.getDateInstance(DateFormat.MEDIUM, locale).format(date); res += s; while (res.length() < SPACES_CDATE) res += " "; } catch (ParseException e) { e.printStackTrace(); log.log(Level.DEBUG, e.getLocalizedMessage()); } date = null; s = null; try { date = DateFormat.getDateTimeInstance().parse(t[3]); s = DateFormat.getDateInstance(DateFormat.MEDIUM, locale).format(date); res += s; while (res.length() < SPACES_EDATE) res += " "; } catch (ParseException e) { e.printStackTrace(); log.log(Level.DEBUG, e.getLocalizedMessage()); } return res; }
From source file:com.rogchen.common.xml.UtilDateTime.java
public static String toGmtTimestampString(Timestamp timestamp) { DateFormat df = DateFormat.getDateTimeInstance(); df.setTimeZone(TimeZone.getTimeZone("GMT")); return df.format(timestamp); }
From source file:entity.files.SYSFilesTools.java
/** * Standard Druck Routine. Nimmt einen HTML Text entgegen und ffnet den lokal installierten Browser damit. * Erstellt temporre Dateien im temp Verzeichnis opde<irgendwas>.html * * @param html//from w ww.j a va2s. c o m * @param addPrintJScript Auf Wunsch kann an das HTML automatisch eine JScript Druckroutine angehangen werden. */ public static File print(String html, boolean addPrintJScript) { File temp = null; try { // Create temp file. temp = File.createTempFile("opde", ".html"); String text = "<html><head>"; if (addPrintJScript) { text += "<script type=\"text/javascript\">" + "window.onload = function() {" + "window.print();" + "}</script>"; } text += OPDE.getCSS(); text += "</head><body>" + SYSTools.htmlUmlautConversion(html) + "<hr/>" + "<div id=\"fonttext\">" + "<b>" + SYSTools.xx("misc.msg.endofreport") + "</b><br/>" + (OPDE.getLogin() != null ? SYSTools.htmlUmlautConversion(OPDE.getLogin().getUser().getUID()) : "") + "<br/>" + DateFormat.getDateTimeInstance().format(new Date()) + "<br/>" + OPDE.getAppInfo().getProgname() + ", v" + OPDE.getAppInfo().getVersion() + "/" + OPDE.getAppInfo().getBuildnum() + "</div></body></html>"; // Write to temp file BufferedWriter out = new BufferedWriter(new FileWriter(temp)); out.write(text); out.close(); SYSFilesTools.handleFile(temp, Desktop.Action.OPEN); } catch (IOException e) { OPDE.error(e); } return temp; }
From source file:org.apache.wiki.auth.user.XMLUserDatabase.java
/** * Tries to parse a date using the default format - then, for backwards * compatibility reasons, tries the platform default. * /* www .j a v a 2s .c o m*/ * @param profile * @param date * @return A parsed date, or null, if both parse attempts fail. */ private Date parseDate(UserProfile profile, String date) { try { DateFormat c_format = new SimpleDateFormat(DATE_FORMAT); return c_format.parse(date); } catch (ParseException e) { try { return DateFormat.getDateTimeInstance().parse(date); } catch (ParseException e2) { log.warn("Could not parse 'created' or 'lastModified' " + "attribute for " + " profile '" + profile.getLoginName() + "'." + " It may have been tampered with."); } } return null; }
From source file:com.f8full.casserolesencours.CasserolesEnCoursActivity.java
public void onViewerModeClick(View view) { //TODO: View only my data on the map /*if(mViewOnMasterID == null) {//from w ww .ja v a 2s.c o m toastMessage(getString(R.string.anonimizeRequired)); return; }*/ String timeFilter = ((Spinner) findViewById(R.id.timeFilterSpinner)).getSelectedItem().toString(); String distanceFilter = ((Spinner) findViewById(R.id.distanceFilterSpinner)).getSelectedItem().toString(); String whereClause = ""; if (distanceFilter.equals("--") == false) //time filtering requested by user { if (mAlohar.getPlaceManager().getCurrentLocation().getLatitude() == 0.0 || mAlohar.getPlaceManager().getCurrentLocation().getLongitude() == 0.0) { //Location not available toastMessage(getString(R.string.locationFilterError)); } else { String WhereClauseDistanceFilter = ""; switch (((Spinner) findViewById(R.id.distanceFilterSpinner)).getSelectedItemPosition()) { case 1: WhereClauseDistanceFilter = "100"; break; case 2: WhereClauseDistanceFilter = "300"; break; case 3: WhereClauseDistanceFilter = "500"; break; case 4: WhereClauseDistanceFilter = "1000"; break; case 5: WhereClauseDistanceFilter = "20000"; break; } //double testLat = 45.5334; //double testLong = -73.5838; //WHERE Pharmacy='yes' AND whereClause += "WHERE ST_INTERSECTS(Location, CIRCLE(LATLNG(" + Double.toString(mAlohar.getPlaceManager().getCurrentLocation().getLatitude()) //+ Double.toString(testLat) + "," + Double.toString(mAlohar.getPlaceManager().getCurrentLocation().getLongitude()) //+ Double.toString(testLong) + ")," + WhereClauseDistanceFilter + ")) "; //37.3242,-121.9806),5000))" } } if (timeFilter.equals("--") == false) //time filtering requested by user { if (whereClause.isEmpty() == false) { whereClause += "AND "; } else { whereClause += "WHERE "; } Calendar cl = Calendar.getInstance(); cl.setTime(new Date()); switch (((Spinner) findViewById(R.id.timeFilterSpinner)).getSelectedItemPosition()) { case 1: cl.add(Calendar.MINUTE, -5); break; case 2: cl.add(Calendar.MINUTE, -15); break; case 3: cl.add(Calendar.MINUTE, -45); break; case 4: cl.add(Calendar.HOUR, -2); break; } whereClause += "Date>='" + DateFormat.getDateTimeInstance().format(cl.getTime()) + "' "; } //1cmlx9aChHUYTWwYivaZucr7NHNsP_ulvEPX1FoM is master table public view ID String fromTableID = "1cmlx9aChHUYTWwYivaZucr7NHNsP_ulvEPX1FoM"; if (((CheckBox) findViewById(R.id.myDataCheckbox)).isChecked()) { fromTableID = mViewOnMasterID; } //excellent, just do a request to grab the locations and pass them around final String SqlQuery = "SELECT Date, Location, Description FROM " + fromTableID + " " + whereClause + "ORDER BY Date DESC LIMIT " + ((EditText) findViewById(R.id.nbIconsMax)).getText(); final boolean myLocationEnabled = !(((CheckBox) findViewById(R.id.worldMapChkBx)).isChecked()); final boolean timeColored = ((CheckBox) findViewById(R.id.timeColoredCheckbox)).isChecked(); new Thread((new Runnable() { public void run() { try { String encodedQuery = URLEncoder.encode(SqlQuery, "UTF-8"); GoogleUrl GUrl = new GoogleUrl(SERVICE_URL + "?sql=" + encodedQuery + "&encid=true"); HttpRequest request = mGOOGClient.getRequestFactory().buildGetRequest(GUrl); HttpHeaders headers = new HttpHeaders(); headers.setContentLength("0");//Required so that Fusion Table API considers request request.setHeaders(headers); HttpResponse response = request.execute(); if (response.getStatusCode() == 200) { //Here I have my data InputStreamReader inputStreamReader = new InputStreamReader(response.getContent()); BufferedReader bufferedStreamReader = new BufferedReader(inputStreamReader); CSVReader reader = new CSVReader(bufferedStreamReader); // The first line is the column names, and the remaining lines are the rows. List<String[]> csvLines = reader.readAll(); List<String> columns = Arrays.asList(csvLines.get(0)); List<String[]> rows = csvLines.subList(1, csvLines.size()); if (rows.size() == 0) { toastMessage("Table vide !"); return; } ArrayList<String> rowData = new ArrayList<String>(); for (String[] row : rows) { String toAdd = ""; for (String cell : row) { //No , in data, or things are gonna go horribly wrong here toAdd += cell + "|"; } //I have this last pesky separator ,it will give me an empty String on the other side rowData.add(toAdd); } Intent mapIntent = new Intent(getApplicationContext(), CasserolesEnCoursViewerActivity.class); mapIntent.putStringArrayListExtra("rowsData", rowData); mapIntent.putExtra("timeColored", timeColored); mapIntent.putExtra("myLocation", myLocationEnabled); if (myLocationEnabled) toastMessage(getString(R.string.lastContributionTapHintLocal)); else toastMessage(getString(R.string.lastContributionTapHintWorld)); //mapIntent.putExtra("relativeTime", ((CheckBox)findViewById(R.id.relativeTimeCheckbox)).isChecked()); startActivity(mapIntent); } } catch (HttpResponseException e) { if (e.getStatusCode() == 401) { mGOOGCredential.setAccessToken(null); SharedPreferences.Editor editor2 = mPrefs.edit(); editor2.remove(PREF_REFRESH_TOKEN); editor2.commit(); toastMessage("OAuth login required, redirecting..."); //This last Constant is weird startActivityForResult( new Intent().setClass(getApplicationContext(), OAuth2AccessTokenActivity.class), REQUEST_OAUTH2_AUTHENTICATE); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } })).start(); }
From source file:de.knowwe.defi.usermanager.XMLUserDatabase.java
/** * Tries to parse a date using the default format - then, for backwards * compatibility reasons, tries the platform default. * //from w ww .j av a 2 s .c om * @param profile * @param date * @return A parsed date, or null, if both parse attempts fail. */ private Date parseDate(UserProfile profile, String date) { try { DateFormat c_format = new SimpleDateFormat(DATE_FORMAT); return c_format.parse(date); } catch (ParseException e) { try { return DateFormat.getDateTimeInstance().parse(date); } catch (ParseException e2) { Log.warning("Could not parse 'created' or 'lastModified' " + "attribute for " + " profile '" + profile.getLoginName() + "'." + " It may have been tampered with."); } } return null; }
From source file:entity.files.SYSFilesTools.java
public static File getHtmlFile(String html, String prefix, String ext) { File temp = null;/*from w ww. ja v a2 s . c o m*/ try { // Create temp file. temp = File.createTempFile(prefix, ext); String text = "<html><head>"; text += OPDE.getCSS(); text += "</head><body>" + SYSTools.htmlUmlautConversion(html) + "<hr/>" + "<div id=\"fonttext\">" + "<b>" + SYSTools.xx("misc.msg.endofreport") + "</b><br/>" + (OPDE.getLogin() != null ? SYSTools.htmlUmlautConversion(OPDE.getLogin().getUser().getUID()) : "") + "<br/>" + DateFormat.getDateTimeInstance().format(new Date()) + "<br/>" + OPDE.getAppInfo().getProgname() + ", v" + OPDE.getAppInfo().getVersion() + "/" + OPDE.getAppInfo().getBuildnum() + "</div></body></html>"; // Write to temp file BufferedWriter out = new BufferedWriter(new FileWriter(temp)); out.write(text); out.close(); } catch (IOException e) { OPDE.error(e); } return temp; }
From source file:org.dawnsci.commandserver.ui.view.StatusQueueView.java
protected void createColumns() { final TableViewerColumn name = new TableViewerColumn(viewer, SWT.LEFT); name.getColumn().setText("Name"); name.getColumn().setWidth(260);//from w w w .j a v a 2s . c om name.setLabelProvider(new ColumnLabelProvider() { public String getText(Object element) { return ((StatusBean) element).getName(); } }); final TableViewerColumn status = new TableViewerColumn(viewer, SWT.LEFT); status.getColumn().setText("Status"); status.getColumn().setWidth(140); status.setLabelProvider(new ColumnLabelProvider() { public String getText(Object element) { return ((StatusBean) element).getStatus().toString(); } }); final TableViewerColumn pc = new TableViewerColumn(viewer, SWT.CENTER); pc.getColumn().setText("Complete (%)"); pc.getColumn().setWidth(120); pc.setLabelProvider(new ColumnLabelProvider() { public String getText(Object element) { try { return NumberFormat.getPercentInstance() .format(((StatusBean) element).getPercentComplete() / 100d); } catch (Exception ne) { return "-"; } } }); final TableViewerColumn submittedDate = new TableViewerColumn(viewer, SWT.CENTER); submittedDate.getColumn().setText("Date Submitted"); submittedDate.getColumn().setWidth(150); submittedDate.setLabelProvider(new ColumnLabelProvider() { public String getText(Object element) { try { return DateFormat.getDateTimeInstance() .format(new Date(((StatusBean) element).getSubmissionTime())); } catch (Exception e) { return e.getMessage(); } } }); final TableViewerColumn message = new TableViewerColumn(viewer, SWT.LEFT); message.getColumn().setText("Message"); message.getColumn().setWidth(150); message.setLabelProvider(new ColumnLabelProvider() { public String getText(Object element) { try { return ((StatusBean) element).getMessage(); } catch (Exception e) { return e.getMessage(); } } }); final TableViewerColumn location = new TableViewerColumn(viewer, SWT.LEFT); location.getColumn().setText("Location"); location.getColumn().setWidth(300); location.setLabelProvider(new ColumnLabelProvider() { public String getText(Object element) { try { final StatusBean bean = (StatusBean) element; return bean.getRunDirectory(); } catch (Exception e) { return e.getMessage(); } } public Color getForeground(Object element) { return getSite().getShell().getDisplay().getSystemColor(SWT.COLOR_BLUE); } }); final TableViewerColumn host = new TableViewerColumn(viewer, SWT.CENTER); host.getColumn().setText("Host"); host.getColumn().setWidth(150); host.setLabelProvider(new ColumnLabelProvider() { public String getText(Object element) { try { return ((StatusBean) element).getHostName(); } catch (Exception e) { return e.getMessage(); } } }); final TableViewerColumn user = new TableViewerColumn(viewer, SWT.CENTER); user.getColumn().setText("User Name"); user.getColumn().setWidth(150); user.setLabelProvider(new ColumnLabelProvider() { public String getText(Object element) { try { return ((StatusBean) element).getUserName(); } catch (Exception e) { return e.getMessage(); } } }); MouseMoveListener cursorListener = new MouseMoveListener() { @Override public void mouseMove(MouseEvent e) { Point pt = new Point(e.x, e.y); TableItem item = viewer.getTable().getItem(pt); if (item == null) { viewer.getTable().setCursor(null); return; } Rectangle rect = item.getBounds(5); if (rect.contains(pt)) { viewer.getTable().setCursor(Display.getDefault().getSystemCursor(SWT.CURSOR_HAND)); } else { viewer.getTable().setCursor(null); } } }; viewer.getTable().addMouseMoveListener(cursorListener); MouseAdapter mouseClick = new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Point pt = new Point(e.x, e.y); TableItem item = viewer.getTable().getItem(pt); if (item == null) return; Rectangle rect = item.getBounds(5); if (rect.contains(pt)) { final StatusBean bean = (StatusBean) item.getData(); openResults(bean); } } }; viewer.getTable().addMouseListener(mouseClick); }