List of usage examples for java.text DateFormat MEDIUM
int MEDIUM
To view the source code for java.text DateFormat MEDIUM.
Click Source Link
From source file:at.alladin.rmbt.mapServer.MarkerResource.java
@Post("json") public String request(final String entity) { addAllowOrigin();//w w w. ja v a 2 s.c o m final MapServerOptions mso = MapServerOptions.getInstance(); final Classification classification = Classification.getInstance(); JSONObject request = null; final JSONObject answer = new JSONObject(); if (entity != null && !entity.isEmpty()) // try parse the string to a JSON object try { request = new JSONObject(entity); String lang = request.optString("language"); // Load Language Files for Client final List<String> langs = Arrays .asList(settings.getString("RMBT_SUPPORTED_LANGUAGES").split(",\\s*")); if (langs.contains(lang)) labels = ResourceManager.getSysMsgBundle(new Locale(lang)); else lang = settings.getString("RMBT_DEFAULT_LANGUAGE"); // System.out.println(request.toString(4)); final JSONObject coords = request.getJSONObject("coords"); final int zoom; double geo_x = 0; double geo_y = 0; int size = 0; boolean useXY = false; boolean useLatLon = false; if (coords.has("x") && coords.has("y")) useXY = true; else if (coords.has("lat") && coords.has("lon")) useLatLon = true; if (coords.has("z") && (useXY || useLatLon)) { zoom = coords.optInt("z"); if (useXY) { geo_x = coords.optDouble("x"); geo_y = coords.optDouble("y"); } else if (useLatLon) { final double tmpLat = coords.optDouble("lat"); final double tmpLon = coords.optDouble("lon"); geo_x = GeoCalc.lonToMeters(tmpLon); geo_y = GeoCalc.latToMeters(tmpLat); // System.out.println(String.format("using %f/%f", geo_x, geo_y)); } if (coords.has("size")) size = coords.getInt("size"); if (zoom != 0 && geo_x != 0 && geo_y != 0) { double radius = 0; if (size > 0) radius = size * GeoCalc.getResFromZoom(256, zoom); // TODO use real tile size else radius = CLICK_RADIUS * GeoCalc.getResFromZoom(256, zoom); // TODO use real tile size final double geo_x_min = geo_x - radius; final double geo_x_max = geo_x + radius; final double geo_y_min = geo_y - radius; final double geo_y_max = geo_y + radius; String hightlightUUIDString = null; UUID highlightUUID = null; final JSONObject mapOptionsObj = request.getJSONObject("options"); String optionStr = mapOptionsObj.optString("map_options"); if (optionStr == null || optionStr.length() == 0) // set // default optionStr = "mobile/download"; final MapOption mo = mso.getMapOptionMap().get(optionStr); final List<SQLFilter> filters = new ArrayList<>(mso.getDefaultMapFilters()); filters.add(mso.getAccuracyMapFilter()); final JSONObject mapFilterObj = request.getJSONObject("filter"); final Iterator<?> keys = mapFilterObj.keys(); while (keys.hasNext()) { final String key = (String) keys.next(); if (mapFilterObj.get(key) instanceof Object) if (key.equals("highlight")) hightlightUUIDString = mapFilterObj.getString(key); else { final MapFilter mapFilter = mso.getMapFilterMap().get(key); if (mapFilter != null) filters.add(mapFilter.getFilter(mapFilterObj.getString(key))); } } if (hightlightUUIDString != null) try { highlightUUID = UUID.fromString(hightlightUUIDString); } catch (final Exception e) { highlightUUID = null; } if (conn != null) { PreparedStatement ps = null; ResultSet rs = null; final StringBuilder whereSQL = new StringBuilder(mo.sqlFilter); for (final SQLFilter sf : filters) whereSQL.append(" AND ").append(sf.where); final String sql = String.format("SELECT" + (useLatLon ? " geo_lat lat, geo_long lon" : " ST_X(t.location) x, ST_Y(t.location) y") + ", t.time, t.timezone, t.speed_download, t.speed_upload, t.ping_median, t.network_type," + " t.signal_strength, t.lte_rsrp, t.wifi_ssid, t.network_operator_name, t.network_operator," + " t.network_sim_operator, t.roaming_type, t.public_ip_as_name, " //TODO: sim_operator obsoled by sim_name + " pMob.shortname mobile_provider_name," // TODO: obsoleted by mobile_network_name + " prov.shortname provider_text, t.open_test_uuid," + " COALESCE(mnwk.shortname,mnwk.name) mobile_network_name," + " COALESCE(msim.shortname,msim.name) mobile_sim_name" + (highlightUUID == null ? "" : " , c.uid, c.uuid") + " FROM v_test t" + " LEFT JOIN mccmnc2name mnwk ON t.mobile_network_id=mnwk.uid" + " LEFT JOIN mccmnc2name msim ON t.mobile_sim_id=msim.uid" + " LEFT JOIN provider prov" + " ON t.provider_id=prov.uid" + " LEFT JOIN provider pMob" + " ON t.mobile_provider_id=pMob.uid" + (highlightUUID == null ? "" : " LEFT JOIN client c ON (t.client_id=c.uid AND c.uuid=?)") + " WHERE" + " %s" + " AND location && ST_SetSRID(ST_MakeBox2D(ST_Point(?,?), ST_Point(?,?)), 900913)" + " ORDER BY" + (highlightUUID == null ? "" : " c.uid ASC,") + " t.uid DESC" + " LIMIT 5", whereSQL); // System.out.println("SQL: " + sql); ps = conn.prepareStatement(sql); int i = 1; if (highlightUUID != null) ps.setObject(i++, highlightUUID); for (final SQLFilter sf : filters) i = sf.fillParams(i, ps); ps.setDouble(i++, geo_x_min); ps.setDouble(i++, geo_y_min); ps.setDouble(i++, geo_x_max); ps.setDouble(i++, geo_y_max); // System.out.println("SQL: " + ps.toString()); if (ps.execute()) { final Locale locale = new Locale(lang); final Format format = new SignificantFormat(2, locale); final JSONArray resultList = new JSONArray(); rs = ps.getResultSet(); while (rs.next()) { final JSONObject jsonItem = new JSONObject(); JSONArray jsonItemList = new JSONArray(); // RMBTClient Info if (highlightUUID != null && rs.getString("uuid") != null) jsonItem.put("highlight", true); final double res_x = rs.getDouble(1); final double res_y = rs.getDouble(2); final String openTestUUID = rs.getObject("open_test_uuid").toString(); jsonItem.put("lat", res_x); jsonItem.put("lon", res_y); jsonItem.put("open_test_uuid", "O" + openTestUUID); // marker.put("uid", uid); final Date date = rs.getTimestamp("time"); final String tzString = rs.getString("timezone"); final TimeZone tz = TimeZone.getTimeZone(tzString); final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale); dateFormat.setTimeZone(tz); jsonItem.put("time_string", dateFormat.format(date)); final int fieldDown = rs.getInt("speed_download"); JSONObject singleItem = new JSONObject(); singleItem.put("title", labels.getString("RESULT_DOWNLOAD")); final String downloadString = String.format("%s %s", format.format(fieldDown / 1000d), labels.getString("RESULT_DOWNLOAD_UNIT")); singleItem.put("value", downloadString); singleItem.put("classification", Classification.classify(classification.THRESHOLD_DOWNLOAD, fieldDown)); // singleItem.put("help", "www.rtr.at"); jsonItemList.put(singleItem); final int fieldUp = rs.getInt("speed_upload"); singleItem = new JSONObject(); singleItem.put("title", labels.getString("RESULT_UPLOAD")); final String uploadString = String.format("%s %s", format.format(fieldUp / 1000d), labels.getString("RESULT_UPLOAD_UNIT")); singleItem.put("value", uploadString); singleItem.put("classification", Classification.classify(classification.THRESHOLD_UPLOAD, fieldUp)); // singleItem.put("help", "www.rtr.at"); jsonItemList.put(singleItem); final long fieldPing = rs.getLong("ping_median"); final int pingValue = (int) Math.round(rs.getDouble("ping_median") / 1000000d); singleItem = new JSONObject(); singleItem.put("title", labels.getString("RESULT_PING")); final String pingString = String.format("%s %s", format.format(pingValue), labels.getString("RESULT_PING_UNIT")); singleItem.put("value", pingString); singleItem.put("classification", Classification.classify(classification.THRESHOLD_PING, fieldPing)); // singleItem.put("help", "www.rtr.at"); jsonItemList.put(singleItem); final int networkType = rs.getInt("network_type"); final String signalField = rs.getString("signal_strength"); if (signalField != null && signalField.length() != 0) { final int signalValue = rs.getInt("signal_strength"); final int[] threshold = networkType == 99 || networkType == 0 ? classification.THRESHOLD_SIGNAL_WIFI : classification.THRESHOLD_SIGNAL_MOBILE; singleItem = new JSONObject(); singleItem.put("title", labels.getString("RESULT_SIGNAL")); singleItem.put("value", signalValue + " " + labels.getString("RESULT_SIGNAL_UNIT")); singleItem.put("classification", Classification.classify(threshold, signalValue)); jsonItemList.put(singleItem); } final String lteRsrpField = rs.getString("lte_rsrp"); if (lteRsrpField != null && lteRsrpField.length() != 0) { final int lteRsrpValue = rs.getInt("lte_rsrp"); final int[] threshold = classification.THRESHOLD_SIGNAL_RSRP; singleItem = new JSONObject(); singleItem.put("title", labels.getString("RESULT_LTE_RSRP")); singleItem.put("value", lteRsrpValue + " " + labels.getString("RESULT_LTE_RSRP_UNIT")); singleItem.put("classification", Classification.classify(threshold, lteRsrpValue)); jsonItemList.put(singleItem); } jsonItem.put("measurement", jsonItemList); jsonItemList = new JSONArray(); singleItem = new JSONObject(); singleItem.put("title", labels.getString("RESULT_NETWORK_TYPE")); singleItem.put("value", Helperfunctions.getNetworkTypeName(networkType)); jsonItemList.put(singleItem); if (networkType == 98 || networkType == 99) // mobile wifi or browser { String providerText = MoreObjects.firstNonNull( rs.getString("provider_text"), rs.getString("public_ip_as_name")); if (!Strings.isNullOrEmpty(providerText)) { if (providerText.length() > (MAX_PROVIDER_LENGTH + 3)) { providerText = providerText.substring(0, MAX_PROVIDER_LENGTH) + "..."; } singleItem = new JSONObject(); singleItem.put("title", labels.getString("RESULT_PROVIDER")); singleItem.put("value", providerText); jsonItemList.put(singleItem); } if (networkType == 99) // mobile wifi { if (highlightUUID != null && rs.getString("uuid") != null) // own test { final String ssid = rs.getString("wifi_ssid"); if (ssid != null && ssid.length() != 0) { singleItem = new JSONObject(); singleItem.put("title", labels.getString("RESULT_WIFI_SSID")); singleItem.put("value", ssid.toString()); jsonItemList.put(singleItem); } } } } else // mobile { String networkOperator = rs.getString("network_operator"); String mobileNetworkName = rs.getString("mobile_network_name"); String simOperator = rs.getString("network_sim_operator"); String mobileSimName = rs.getString("mobile_sim_name"); final int roamingType = rs.getInt("roaming_type"); //network if (!Strings.isNullOrEmpty(networkOperator)) { final String mobileNetworkString; if (roamingType != 2) { //not international roaming - display name of home network if (Strings.isNullOrEmpty(mobileSimName)) mobileNetworkString = networkOperator; else mobileNetworkString = String.format("%s (%s)", mobileSimName, networkOperator); } else { //international roaming - display name of network if (Strings.isNullOrEmpty(mobileSimName)) mobileNetworkString = networkOperator; else mobileNetworkString = String.format("%s (%s)", mobileNetworkName, networkOperator); } singleItem = new JSONObject(); singleItem.put("title", labels.getString("RESULT_MOBILE_NETWORK")); singleItem.put("value", mobileNetworkString); jsonItemList.put(singleItem); } //home network (sim) else if (!Strings.isNullOrEmpty(simOperator)) { final String mobileNetworkString; if (Strings.isNullOrEmpty(mobileSimName)) mobileNetworkString = simOperator; else mobileNetworkString = String.format("%s (%s)", mobileSimName, simOperator); /* if (!Strings.isNullOrEmpty(mobileProviderName)) { mobileNetworkString = mobileProviderName; } else { mobileNetworkString = simOperator; } */ singleItem = new JSONObject(); singleItem.put("title", labels.getString("RESULT_HOME_NETWORK")); singleItem.put("value", mobileNetworkString); jsonItemList.put(singleItem); } if (roamingType > 0) { singleItem = new JSONObject(); singleItem.put("title", labels.getString("RESULT_ROAMING")); singleItem.put("value", Helperfunctions.getRoamingType(labels, roamingType)); jsonItemList.put(singleItem); } } jsonItem.put("net", jsonItemList); resultList.put(jsonItem); if (resultList.length() == 0) System.out.println("Error getting Results."); // errorList.addError(MessageFormat.format(labels.getString("ERROR_DB_GET_CLIENT"), // new Object[] {uuid})); } answer.put("measurements", resultList); } else System.out.println("Error executing SQL."); } else System.out.println("No Database Connection."); } } else System.out.println("Expected request is missing."); } catch (final JSONException e) { System.out.println("Error parsing JSDON Data " + e.toString()); } catch (final SQLException e) { e.printStackTrace(); } else System.out.println("No Request."); return answer.toString(); }
From source file:mobisocial.bento.anyshare.util.DBHelper.java
public long storeLinkobjInDatabase(DbObj obj, Context context) { long localId = -1; // if replace entry, set ID long hash = obj.getHash(); Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_html); byte[] raw = BitmapHelper.bitmapToBytes(icon); String feedname = obj.getFeedName(); long parentid = 0; try {/* w w w . jav a 2 s. c o m*/ if (obj.getJson().has("target_relation") && obj.getJson().getString("target_relation").equals("parent") && obj.getJson().has("target_hash")) { parentid = objIdForHash(obj.getJson().getLong("target_hash")); } } catch (JSONException e) { e.printStackTrace(); } DbUser usr = obj.getSender(); String sender = ""; if (usr != null) { sender = usr.getName(); } long timestamp = 0; String title = ""; try { timestamp = Long.parseLong(obj.getJson().getString("timestamp")); title = obj.getJson().getString("title"); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } // add object long objId = (localId == -1) ? getNextId() : localId; String desc = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT) .format(new Date(timestamp)); if (!sender.isEmpty()) { desc += " by " + sender; } ContentValues cv = new ContentValues(); cv.put(ItemObject._ID, objId); cv.put(ItemObject.FEEDNAME, feedname); cv.put(ItemObject.TITLE, title); cv.put(ItemObject.DESC, desc); cv.put(ItemObject.TIMESTAMP, timestamp); cv.put(ItemObject.OBJHASH, hash); cv.put(ItemObject.PARENT_ID, parentid); if (raw != null) { cv.put(ItemObject.RAW, raw); } long newObjId = getWritableDatabase().insertOrThrow(ItemObject.TABLE, null, cv); return objId; }
From source file:mitm.common.security.certificate.GenerateTestCertificates.java
private void generateValidCertificate() throws Exception { X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder(); String encodedPrivateKey = "30820276020100300d06092a864886f70d0101010500048202603082025c" + "02010002818100a9fee3017954c99b248d1486830c71b2e0ea3f9b7a2763" + "1bed8a731f5bd7e1edf856bc3fb7c63dedbeb5bb0de474e7792b3aa7e7b2" + "274c03a47c7d89b1935eaef172c6395f2322f1ed9e61ae46d716b4b4394c" + "1a802db05a2d7c3d1d41a3e8afc65ff8dada7414744f1ee1540e50ee7fb8" + "db437b20c5ee33a82b9d575cfbc951020301000102818004f84ab2b45562" + "3f82e60cff91bd3f65b765a1ce6dd7d0f1f413e421ba91a92d47e161478b" + "9be41b9b43bce03f199bdad304b7fbf21d6bff7f439477fe150ce38c312f" + "c015f3c89291aaa42c4c106f623dfd9f76acad2f1c77b590f038ffbb25f9" + "14b6f7ead769808ddd0e2d648442620b50518d9b7fb132b2fa1fa3e9d628" + "41024100e69ab3765120d0e0ba5dc21bf384b2f553211b4b1902175454c6" + "2f1b0f8ad385d78490539308c9fd5145ae36cc2a6d364fdd97d83d9b6623" + "a987db239e716055024100bcb77acf1e9829ab5b2c9a5e73d343db857474" + "a529ba52ca256655eb7d760e85d3c68eec9500e3db0494c8f77cb8058593" + "6e52a9290149367392d74ecdc3510d024100bd15723b7cb024b56ffabad3" + "c26c3774f2b1bdb8690c0ee7060feec6088b737f56450b368be4740332e5" + "a8c0a3cdd1f8eba9adfd101ee0b43329036584604075024055465b9a27ea" + "fe394e33b375a6c4fa4ec1d943b4364cd9883aaa297d05ee48d5b4426ee6" + "fcd5b02091cb619c63a10bedb6170e071e5e5464e4889ffe1e007a290240" + "7b60d23994a2ec38db909678446ed56d32455bf684141b9ee0aec68b2025" + "1d4d94fd2beebf02074559b811ae1130d2e2aa3bec2e9bccb06969104856" + "00c70759"; String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d0030818902818100a9" + "fee3017954c99b248d1486830c71b2e0ea3f9b7a27631bed8a731f5bd7e1" + "edf856bc3fb7c63dedbeb5bb0de474e7792b3aa7e7b2274c03a47c7d89b1" + "935eaef172c6395f2322f1ed9e61ae46d716b4b4394c1a802db05a2d7c3d" + "1d41a3e8afc65ff8dada7414744f1ee1540e50ee7fb8db437b20c5ee33a8" + "2b9d575cfbc9510203010001"; PrivateKey privateKey = decodePrivateKey(encodedPrivateKey); PublicKey publicKey = decodePublicKey(encodedPublicKey); X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder(); String email = "test@example.com"; subjectBuilder.setCommonName("Valid certificate"); subjectBuilder.setEmail(email);//from w ww . j a v a 2 s . c o m subjectBuilder.setCountryCode("NL"); subjectBuilder.setLocality("Amsterdam"); subjectBuilder.setState("NH"); AltNamesBuilder altNamesBuider = new AltNamesBuilder(); altNamesBuider.setRFC822Names(email); X500Principal subject = subjectBuilder.buildPrincipal(); GeneralNames altNames = altNamesBuider.buildAltNames(); // use TreeSet because we want a deterministic certificate (ie. hash should not change) Set<KeyUsageType> keyUsage = new TreeSet<KeyUsageType>(); keyUsage.add(KeyUsageType.DIGITALSIGNATURE); keyUsage.add(KeyUsageType.KEYENCIPHERMENT); keyUsage.add(KeyUsageType.NONREPUDIATION); Set<ExtendedKeyUsageType> extendedKeyUsage = new TreeSet<ExtendedKeyUsageType>(); extendedKeyUsage.add(ExtendedKeyUsageType.CLIENTAUTH); extendedKeyUsage.add(ExtendedKeyUsageType.EMAILPROTECTION); BigInteger serialNumber = new BigInteger("115fcd741088707366e9727452c9770", 16); Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK) .parse("21-Nov-2007 10:38:35"); certificateBuilder.setSubject(subject); certificateBuilder.setAltNames(altNames, true); certificateBuilder.setKeyUsage(keyUsage, true); certificateBuilder.setExtendedKeyUsage(extendedKeyUsage, false); certificateBuilder.setNotBefore(DateUtils.addDays(now, -20)); certificateBuilder.setNotAfter(DateUtils.addYears(now, 20)); certificateBuilder.setPublicKey(publicKey); certificateBuilder.setSerialNumber(serialNumber); certificateBuilder.setSignatureAlgorithm("SHA1WithRSAEncryption"); certificateBuilder.addSubjectKeyIdentifier(true); X509Certificate certificate = certificateBuilder.generateCertificate(caPrivateKey, caCertificate); assertNotNull(certificate); certificates.add(certificate); Certificate[] chain = new Certificate[] { certificate, caCertificate, rootCertificate }; keyStore.setKeyEntry("ValidCertificate", privateKey, null, chain); }
From source file:com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.java
private Object doConvertToDate(Map<String, Object> context, Object value, Class toType) { Date result = null;/*from w ww . j ava2 s. c o m*/ if (value instanceof String && value != null && ((String) value).length() > 0) { String sa = (String) value; Locale locale = getLocale(context); DateFormat df = null; if (java.sql.Time.class == toType) { df = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale); } else if (java.sql.Timestamp.class == toType) { Date check = null; SimpleDateFormat dtfmt = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale); SimpleDateFormat fullfmt = new SimpleDateFormat(dtfmt.toPattern() + MILLISECOND_FORMAT, locale); SimpleDateFormat dfmt = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale); SimpleDateFormat[] fmts = { fullfmt, dtfmt, dfmt }; for (SimpleDateFormat fmt : fmts) { try { check = fmt.parse(sa); df = fmt; if (check != null) { break; } } catch (ParseException ignore) { } } } else if (java.util.Date.class == toType) { Date check = null; DateFormat[] dfs = getDateFormats(locale); for (DateFormat df1 : dfs) { try { check = df1.parse(sa); df = df1; if (check != null) { break; } } catch (ParseException ignore) { } } } //final fallback for dates without time if (df == null) { df = DateFormat.getDateInstance(DateFormat.SHORT, locale); } try { df.setLenient(false); // let's use strict parsing (XW-341) result = df.parse(sa); if (!(Date.class == toType)) { try { Constructor constructor = toType.getConstructor(new Class[] { long.class }); return constructor.newInstance(new Object[] { Long.valueOf(result.getTime()) }); } catch (Exception e) { throw new XWorkException( "Couldn't create class " + toType + " using default (long) constructor", e); } } } catch (ParseException e) { throw new XWorkException("Could not parse date", e); } } else if (Date.class.isAssignableFrom(value.getClass())) { result = (Date) value; } return result; }
From source file:DDTDate.java
/** * This function will populate the varsMap with new copies of values related to display format of date & time stamps. * Those values are based on the class (static) date variable that is currently in use. * Those values can later be used in verification of UI elements that are date-originated but may change in time (say, today's date, month, year - etc.) * The base date that is used is Locale dependent (currently, the local is assumed to be that of the workstation running the software.) * When relevant, values are provided in various styles (SHORT, MEDIUM, LONG, FULL) - not all date elements have all those versions available. * The purpose of this 'exercise' is to set up the facility for the user to verify any component of date / time stamps independently of one another or 'traditional' formatting. * * The variables maintained here are formatted with a prefix to distinguish them from other, user defined variables. * * @TODO: enable Locale modifications (at present the test machine's locale is considered and within a test session only one locale can be tested) * @param varsMap/*from w w w.j a v a 2s . c o m*/ */ private void maintainDateProperties(Hashtable<String, Object> varsMap) throws Exception { String prefix = "$"; try { // Build formatting objects for each of the output styles DateFormat shortStyleFormatter = DateFormat.getDateInstance(DateFormat.SHORT); DateFormat mediumStyleFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM); DateFormat longStyleFormatter = DateFormat.getDateInstance(DateFormat.LONG); DateFormat fullStyleFormatter = DateFormat.getDateInstance(DateFormat.FULL); // Use a dedicated variable to hold values of formatting results to facilitate debugging // @TODO (maybe) when done debugging - convert to inline calls to maintainDateProperty ... String formatValue; // Examples reflect time around midnight of February 6 2014 - actual values DO NOT include quotes (added here for readability) MutableDateTime theReferenceDate = getReferenceDate(); //getReferenceDateAdjustedForTimeZone(); // Default Date using DDTSettings pattern. formatValue = new SimpleDateFormat(defaultDateFormat()).format(theReferenceDate.toDate()); maintainDateProperty(prefix + "defaultDate", formatValue, varsMap); // Short Date - '2/6/14' formatValue = shortStyleFormatter.format(theReferenceDate.toDate()); maintainDateProperty(prefix + "shortDate", formatValue, varsMap); // Medium Date - 'Feb 6, 2014' formatValue = mediumStyleFormatter.format(theReferenceDate.toDate()); maintainDateProperty(prefix + "mediumDate", formatValue, varsMap); // Long Date - 'February 6, 2014' formatValue = longStyleFormatter.format(theReferenceDate.toDate()); maintainDateProperty(prefix + "longDate", formatValue, varsMap); // Full Date 'Thursday, February 6, 2014' formatValue = fullStyleFormatter.format(theReferenceDate.toDate()); maintainDateProperty(prefix + "fullDate", formatValue, varsMap); // hours : minutes : seconds : milliseconds (broken to separate components) - formatValue = theReferenceDate.toString("hh:mm:ss:SSS"); if (formatValue.toString().contains(":")) { String[] hms = split(formatValue.toString(), ":"); if (hms.length > 3) { // Hours - '12' formatValue = hms[0]; maintainDateProperty(prefix + "hours", formatValue, varsMap); // Minutes - '02' formatValue = hms[1]; maintainDateProperty(prefix + "minutes", formatValue, varsMap); // Seconds - '08' formatValue = hms[2]; maintainDateProperty(prefix + "seconds", formatValue, varsMap); // Milliseconds - '324' formatValue = hms[3]; maintainDateProperty(prefix + "milliseconds", formatValue, varsMap); // Hours in 24 hours format - '23' formatValue = theReferenceDate.toString("HH"); maintainDateProperty(prefix + "hours24", formatValue, varsMap); } else setException("Failed to format reference date to four time units!"); } else { setException("Failed to format reference date to its time units!"); } // hours : minutes : seconds (default timestamp) - '12:34:56' formatValue = theReferenceDate.toString("hh:mm:ss"); maintainDateProperty(prefix + "timeStamp", formatValue, varsMap); // Short Year - '14' formatValue = theReferenceDate.toString("yy"); maintainDateProperty(prefix + "shortYear", formatValue, varsMap); // Long Year - '2014' formatValue = theReferenceDate.toString("yyyy"); maintainDateProperty(prefix + "longYear", formatValue, varsMap); // Short Month - '2' formatValue = theReferenceDate.toString("M"); maintainDateProperty(prefix + "shortMonth", formatValue, varsMap); // Padded Month - '02' formatValue = theReferenceDate.toString("MM"); maintainDateProperty(prefix + "paddedMonth", formatValue, varsMap); // Short Month Name - 'Feb' formatValue = theReferenceDate.toString("MMM"); maintainDateProperty(prefix + "shortMonthName", formatValue, varsMap); // Long Month Name - 'February' formatValue = theReferenceDate.toString("MMMM"); maintainDateProperty(prefix + "longMonthName", formatValue, varsMap); // Week in Year - '2014' (the year in which this week falls) formatValue = String.valueOf(theReferenceDate.getWeekyear()); maintainDateProperty(prefix + "weekYear", formatValue, varsMap); // Short Day in date stamp - '6' formatValue = theReferenceDate.toString("d"); maintainDateProperty(prefix + "shortDay", formatValue, varsMap); // Padded Day in date stamp - possibly with leading 0 - '06' formatValue = theReferenceDate.toString("dd"); maintainDateProperty(prefix + "paddedDay", formatValue, varsMap); // Day of Year - '37' formatValue = theReferenceDate.toString("D"); maintainDateProperty(prefix + "yearDay", formatValue, varsMap); // Short Day Name - 'Thu' formatValue = theReferenceDate.toString("E"); maintainDateProperty(prefix + "shortDayName", formatValue, varsMap); // Long Day Name - 'Thursday' DateTime dt = new DateTime(theReferenceDate.toDate()); DateTime.Property dowDTP = dt.dayOfWeek(); formatValue = dowDTP.getAsText(); maintainDateProperty(prefix + "longDayName", formatValue, varsMap); // AM/PM - 'AM' formatValue = theReferenceDate.toString("a"); maintainDateProperty(prefix + "ampm", formatValue, varsMap); // Era - (BC/AD) formatValue = theReferenceDate.toString("G"); maintainDateProperty(prefix + "era", formatValue, varsMap); // Time Zone - 'EST' formatValue = theReferenceDate.toString("zzz"); maintainDateProperty(prefix + "zone", formatValue, varsMap); addComment( "Date variables replenished for date: " + fullStyleFormatter.format(theReferenceDate.toDate())); addComment(theReferenceDate.toString()); System.out.println(getComments()); } catch (Exception e) { setException(e); } }
From source file:org.jclouds.vfs.tools.blobstore.BlobStoreShell.java
private void ls(FileSystemManager mg, FileObject wd, final String[] cmd) throws FileSystemException { int pos = 1;//from w w w .ja v a2 s . co m final boolean recursive; if (cmd.length > pos && cmd[pos].equals("-R")) { recursive = true; pos++; } else { recursive = false; } final FileObject file; if (cmd.length > pos) { file = mg.resolveFile(wd, cmd[pos]); } else { file = wd; } if (file.getType() == FileType.FOLDER) { // List the contents System.out.println("Contents of " + file.getName().getFriendlyURI()); listChildren(file, recursive, ""); } else { // Stat the file System.out.println(file.getName()); final FileContent content = file.getContent(); System.out.println("Size: " + content.getSize() + " bytes."); final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); final String lastMod = dateFormat.format(new Date(content.getLastModifiedTime())); System.out.println("Last modified: " + lastMod); } }
From source file:com.nma.util.sdcardtrac.GraphFragment.java
private void drawGraph(LinearLayout view, boolean redraw) { float textSize, dispScale, pointSize; // Determine text size dispScale = getActivity().getResources().getDisplayMetrics().density; textSize = (GRAPHVIEW_TEXT_SIZE_DIP * dispScale) + 0.5f; pointSize = (GRAPHVIEW_POINT_SIZE_DIP * dispScale) + 0.5f; storageGraph = new LineGraphView(getActivity(), graphLabel); storageGraph.setCustomLabelFormatter(new CustomLabelFormatter() { String prevDate = ""; @Override// www. j a v a 2s . c o m public String formatLabel(double value, boolean isValueX, int index, int lastIndex) { String retValue; boolean valueXinRange; valueXinRange = (index == 0) || (index == lastIndex); if (isValueX) { // Format time in human readable form if (valueXinRange) { String dateStr; Date currDate = new Date((long) value); dateStr = DateFormat.getDateInstance(DateFormat.MEDIUM).format(currDate); if (dateStr.equals(prevDate)) { // Show hh:mm retValue = DateFormat.getTimeInstance(DateFormat.SHORT).format(currDate); } else { retValue = dateStr; } prevDate = dateStr; //Log.d(getClass().getName(), "Label is : " + retValue); } else { retValue = " "; } } else { // Format size in human readable form retValue = DatabaseLoader.convertToStorageUnits(value); //prevDate = ""; } //return super.formatLabel(value, isValueX); // let the y-value be normal-formatted return retValue; } }); storageGraph.addSeries(graphSeries); storageGraph.setManualYAxis(true); storageGraph.setManualYAxisBounds(maxStorage, 0); storageGraph.setScalable(false); //storageGraph.setScrollable(true); storageGraph.getGraphViewStyle().setGridColor(Color.GREEN); storageGraph.getGraphViewStyle().setHorizontalLabelsColor(Color.YELLOW); storageGraph.getGraphViewStyle().setVerticalLabelsColor(Color.RED); storageGraph.getGraphViewStyle().setTextSize(textSize); storageGraph.getGraphViewStyle().setNumHorizontalLabels(2); storageGraph.getGraphViewStyle().setNumVerticalLabels(5); storageGraph.getGraphViewStyle().setVerticalLabelsWidth((int) (textSize * 4)); //storageGraph.setMultiLineXLabel(true, ";"); ((LineGraphView) storageGraph).setDrawBackground(true); ((LineGraphView) storageGraph).setDrawDataPoints(true); ((LineGraphView) storageGraph).setDataPointsRadius(pointSize); //storageGraph.highlightSample(0, true, locData.size() - 1); // Add selector callback storageGraph.setSelectHandler(this); setViewport(redraw); if (view != null) { view.addView(storageGraph); } if (SettingsActivity.ENABLE_DEBUG) Log.d(getClass().getName(), "Drew the graph, redraw=" + redraw); }
From source file:br.msf.commons.util.AbstractDateUtils.java
public static String formatDate(final Object date, final Locale locale) { final DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM, LocaleUtils.getNullSafeLocale(locale)); return df.format(castToDate(date)); }
From source file:br.msf.commons.util.AbstractDateUtils.java
public static String formatTime(final Object date, final Locale locale) { final DateFormat df = SimpleDateFormat.getTimeInstance(DateFormat.MEDIUM, LocaleUtils.getNullSafeLocale(locale)); return df.format(castToDate(date)); }