List of usage examples for java.util Locale US
Locale US
To view the source code for java.util Locale US.
Click Source Link
From source file:Main.java
/** * Convert the current time in milliseconds to readable string as given format. * Notice: The time is counted since January 1, 1970 00:00:00.0 UTC. * @param format/*from w w w . j av a 2s .c om*/ * y year * M month in the year * d day * h hours(12) * H hours(24) * m minute * s second * S millisecond * E weekday * D days in the year */ public static String convertMillisTime(long time_millis, String format) { if (time_millis <= 0) { return ""; } String result = ""; try { SimpleDateFormat dateFormat = new SimpleDateFormat(format, Locale.US); result = dateFormat.format(new Date(time_millis)); } catch (IllegalArgumentException e) { e.printStackTrace(); } return result; }
From source file:Main.java
/** * Get the ip address for mesh usage(For mesh require the ip address hex uppercase without ".". * /*from w w w . j av a 2s. com*/ * @param hostname the ip address, e.g. 192.168.1.2 * @return ip address by hex without ".", e.g. C0A80102 */ public static String getIpAddressForMesh(String hostname) { StringBuilder sb = new StringBuilder(); String[] segments = hostname.split("\\."); int segment; String segmentHexStr; for (int i = 0; i < segments.length; i++) { // get the integer segment = Integer.parseInt(segments[i]); // transform the integer to hex segmentHexStr = Integer.toHexString(segment); // transform the hex string to uppercase segmentHexStr = segmentHexStr.toUpperCase(Locale.US); // append segmentHexStr to the sb if (segmentHexStr.length() == 1) { sb.append("0"); sb.append(segmentHexStr); } else if (segmentHexStr.length() == 2) { sb.append(segmentHexStr); } else { throw new RuntimeException(); } } return sb.toString(); }
From source file:Main.java
public static String formatDegreesCoordsAsStringNWSE(double degLat, double degLon) { double[] minutesLat = decimalDegreesToDegreeMinutes(degLat); double[] minutesLon = decimalDegreesToDegreeMinutes(degLon); return String.format(Locale.US, (degLat < 0 ? "S" : "N") + " %1$d %2$06.3f " + (degLon < 0 ? "W" : "E") + " %3$d %4$06.3f", (int) minutesLat[0], minutesLat[1], (int) minutesLon[0], minutesLon[1]); }
From source file:Main.java
/** * Checks the validity of an argument, given a condition. If the condition passes, the argument * is returned. If not, an IllegalArgumentException is thrown. * @param arg The argument/* w w w. ja v a 2 s .c o m*/ * @param condition The evaluated condition * @param argName The name of the argument field for use in the exception, if needed. * @return The argument, if condition is valid. * @throws IllegalArgumentException if the condition is invalid */ public static <T> T checkArg(T arg, boolean condition, String argName) { if (condition) { return arg; } throw new IllegalArgumentException(String.format(Locale.US, "Illegal argument for %s.", argName)); }
From source file:Main.java
/** * create a new filename based on the current time * @return/*ww w .j av a 2s . co m*/ */ @SuppressLint("SimpleDateFormat") public static String createFileName() { File pictureFileDir = getAppDir(); // display and log an error when a directory cant be found or created if (!pictureFileDir.exists() && !pictureFileDir.mkdirs()) { Log.d(TAG, "Can't create directory to save image."); return ""; } // create a name for the picture based on the current date SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US); String date = dateFormat.format(new Date()); String photoFile = "Picture_" + date + ".jpg"; String fileName = pictureFileDir.getPath() + File.separator + photoFile; return fileName; }
From source file:Main.java
public static byte[] decodeHex(String str) { str = str.toLowerCase(Locale.US); int len = str.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(str.charAt(i), 16) << 4) + Character.digit(str.charAt(i + 1), 16)); }// w w w . j ava 2s .c o m return data; }
From source file:Main.java
/** * Get simple date format instance/* w w w .ja v a 2 s.c o m*/ * * @param pattern - Patter to make {@link SimpleDateFormat} * @return */ private static SimpleDateFormat getSimpleDateFormat(String pattern) { return new SimpleDateFormat(pattern, Locale.US); }
From source file:Main.java
/** * Converts text to lower case using {@link Locale#US}. * * @param text The text to convert./* w w w .jav a 2 s. co m*/ * @return The lower case text, or null if {@code text} is null. */ public static String toLowerInvariant(String text) { return text == null ? null : text.toLowerCase(Locale.US); }
From source file:Main.java
public static String getFormattedDate(Long millis, String timeZone) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US); if (!TextUtils.isEmpty(timeZone)) sdf.setTimeZone(TimeZone.getTimeZone(timeZone)); return millis != null ? sdf.format(new Date(millis)) : ""; }
From source file:Main.java
private static final Calendar getUtcDate(Date date, boolean noYear) { final Calendar calendar = Calendar.getInstance(UTC_TIMEZONE, Locale.US); calendar.setTime(date);/*from w w w . j av a 2 s .c o m*/ if (noYear) { calendar.set(Calendar.YEAR, 0); } return calendar; }