List of usage examples for java.util Locale getDefault
public static Locale getDefault()
From source file:Main.java
public static String getDateTime(Calendar calendar) { int year = calendar.get(Calendar.YEAR); // if (year>3900) year-=1900; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); //Date date = new Date(); return dateFormat .format(new Date(year - 1900, calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH))); }
From source file:Main.java
public static Calendar toCalendar(String s, String format) { Calendar c = Calendar.getInstance(); SimpleDateFormat simpleDateFormat; simpleDateFormat = new SimpleDateFormat(format, Locale.getDefault()); s = s.replace("T", " "); // car T est invalide try {/*from www. j av a2s . com*/ c.setTime(simpleDateFormat.parse(s)); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return c; }
From source file:Main.java
public static final String convertToColorCode(int color) { int alpha = Color.alpha(color); int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); return String.format(Locale.getDefault(), "%02x%02x%02x%02x", alpha, red, green, blue); }
From source file:Main.java
public static String toLowerCase(String str, int beginIndex, int endIndex) { return str.replaceFirst(str.substring(beginIndex, endIndex), str.substring(beginIndex, endIndex).toLowerCase(Locale.getDefault())); }
From source file:Main.java
public static String prettifyDate(long timestamp) { SimpleDateFormat dateFormat;/*from ww w. j a v a2s. com*/ if (DateUtils.isToday(timestamp)) { dateFormat = new SimpleDateFormat("hh:mm a", Locale.getDefault()); } else { dateFormat = new SimpleDateFormat("dd MMM hh:mm a", Locale.getDefault()); } return dateFormat.format(timestamp); }
From source file:Main.java
public static List<Address> getAddress(Context c, Location loc) throws IOException { Geocoder geocoder = new Geocoder(c, Locale.getDefault()); List<Address> addresses = null; addresses = geocoder.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1); return addresses; }
From source file:Main.java
public static void setLanguage(Context context, String language) { Locale locale;//from w w w . ja v a2 s. com if (TextUtils.isEmpty(language)) { locale = Locale.getDefault(); } else if (language.length() == 5 && language.charAt(2) == '_') { // language is in the form: en_US locale = new Locale(language.substring(0, 2), language.substring(3)); } else { locale = new Locale(language); } Configuration config = new Configuration(); config.locale = locale; Resources resources = context.getResources(); resources.updateConfiguration(config, resources.getDisplayMetrics()); }
From source file:Main.java
public static long getLongDate(String date) { try {/*from w w w. j a v a 2 s. c o m*/ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.getDefault()); sdf.setTimeZone(TimeZone.getDefault()); Date d = sdf.parse(date); return d.getTime(); } catch (Exception e) { e.printStackTrace(); } return 0; }
From source file:Main.java
/** * @Title: getCurrentDate// ww w .j a v a2 s .c om * @Description: TODO * @return String of current date */ public static String getCurrentDate() { Date now = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.getDefault()); return dateFormat.format(now); }
From source file:Main.java
public static int monthsBetweenDates(String start, String end) throws ParseException { SimpleDateFormat format = new SimpleDateFormat("MMMM, yyyy", Locale.getDefault()); Date startDate = format.parse(start); Date endDate = format.parse(end); Calendar startCalendar = new GregorianCalendar(); startCalendar.setTime(startDate);/* w w w. ja v a2 s. co m*/ Calendar endCalendar = new GregorianCalendar(); endCalendar.setTime(endDate); int diffYear = endCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR); return diffYear * 12 + endCalendar.get(Calendar.MONTH) - startCalendar.get(Calendar.MONTH); }