List of usage examples for java.util Locale getDefault
public static Locale getDefault()
From source file:Main.java
/** * millisecondsToHours/*from w ww.ja va 2 s . co m*/ * Get the hh:mm value from milliseconds * @param millis the milliseconds value * @return a string with the time in hh:mm format */ public static String millisecondsToHours(long millis) { return String.format(Locale.getDefault(), "%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis), TimeUnit.MILLISECONDS.toMinutes(millis) % TimeUnit.HOURS.toMinutes(1)); }
From source file:Main.java
public static String getUTCTimeFromLocal(String localTime) { java.util.Date UTCDate = null; String localTimeStr = null;/* www .jav a 2 s. c o m*/ SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault()); try { UTCDate = format.parse(localTime); localTimeStr = format.format(UTCDate.getTime() - TimeZone.getDefault().getRawOffset()); } catch (ParseException e) { e.printStackTrace(); } return localTimeStr; }
From source file:Main.java
public static String getTimeWithFormat(Date date, String format) { if (format == null) { format = "yyyy-MM-dd HH:mm:ss"; }// www.j a v a2s . c o m SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.getDefault()); if (date == null) { date = getDateTimeNow(); } return sdf.format(date); }
From source file:Main.java
private static String replaceInside(String content, String character, String format) { try {/*from www . j a v a 2 s . c o m*/ int index; while ((index = content.indexOf(character)) >= 0) { int endIndex = content.indexOf(character, index + 1); String inside = String.format(Locale.getDefault(), format, content.substring(index + 1, endIndex)); content = content.replace(content.substring(index, endIndex + 1), inside); } } catch (StringIndexOutOfBoundsException e) { e.printStackTrace(); } return content; }
From source file:Main.java
public static final String byteArrayToHexString(byte[] data) { StringBuilder sb = new StringBuilder(data.length * 2); for (byte b : data) { int v = b & 0xff; if (v < 16) { sb.append('0'); }/*from w ww .j a v a 2 s . com*/ sb.append(Integer.toHexString(v)); } return sb.toString().toUpperCase(Locale.getDefault()); }
From source file:Main.java
public static String getCompleteAddressString(Context context, double LATITUDE, double LONGITUDE) { String strAdd = ""; Geocoder geocoder = new Geocoder(context, Locale.getDefault()); try {/* ww w.j a v a 2 s . co m*/ List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1); if (addresses != null) { Address returnedAddress = addresses.get(0); StringBuilder strReturnedAddress = new StringBuilder(""); for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) { strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n"); } strAdd = strReturnedAddress.toString(); Log.w("My Current loction address", "" + strReturnedAddress.toString()); } else { Log.w("My Current loction address", "No Address returned!"); } } catch (Exception e) { e.printStackTrace(); Log.w("My Current loction address", "Canont get Address!"); } return strAdd; }
From source file:Main.java
public static String stringFromDateTime(Date dateTime) throws ParseException { String dateTimeString;/*ww w . j ava 2s.c o m*/ DateFormat dateFormatter; dateFormatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.getDefault()); dateTimeString = dateFormatter.format(dateTime); return dateTimeString; }
From source file:Main.java
public static String bytesToHexString(byte[] src) { if (src == null || src.length <= 0) { return null; }/*from w ww.ja v a 2s.co m*/ String hexStr = ""; for (byte b : src) { String hex = Integer.toHexString(b & 0xFF); if (hex.length() == 1) { hex = '0' + hex; } hexStr += hex.toUpperCase(Locale.getDefault()); } return hexStr; }
From source file:Main.java
public static String getLocalDateTimeFromUTCDateTime(String UTCDateTime) { java.util.Date nowDate = null; String UTCDate = null;//from w w w. j a va2s .c o m SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()); try { nowDate = format.parse(UTCDateTime); UTCDate = format.format(nowDate.getTime() + TimeZone.getDefault().getRawOffset()); } catch (ParseException e) { e.printStackTrace(); } return UTCDate; }
From source file:Main.java
public static String getUTCDateTimeFromLocalDateTime(String localTimeStr) { java.util.Date nowDate = null; String UTCDate = null;//from w w w. j ava 2s. c om SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()); try { nowDate = format.parse(localTimeStr); UTCDate = format.format(nowDate.getTime() - TimeZone.getDefault().getRawOffset()); } catch (ParseException e) { e.printStackTrace(); } return UTCDate; }