Example usage for java.util Locale getDefault

List of usage examples for java.util Locale getDefault

Introduction

In this page you can find the example usage for java.util Locale getDefault.

Prototype

public static Locale getDefault() 

Source Link

Document

Gets the current value of the default locale for this instance of the Java Virtual Machine.

Usage

From source file:Main.java

/**
 * Returns the given amount of meters in rounded yards if the default locale
 * is US, in rounded meters otherwise.// w w w .j  av a 2 s.  c  om
 * @param meters
 * @return int
 */
public static int getLocalizedRoundedMeters(final float meters) {
    Locale defaultLocale = Locale.getDefault();
    if (defaultLocale.equals(Locale.US)) {
        return Math.round(meters / 0.9144f);
    } else {
        return Math.round(meters);
    }
}

From source file:Main.java

public static Locale getLocale(String locale) {
    if (locale == null)
        return Locale.getDefault();

    StringTokenizer localeTokenizer = new StringTokenizer(locale, "_");
    if (localeTokenizer.countTokens() == 1) {
        return new Locale(locale);
    } else {//from   w w  w.  j  a v a 2 s.  co m
        return new Locale(localeTokenizer.nextToken(), localeTokenizer.nextToken());
    }
}

From source file:Main.java

/**
 * Converts time to a string, e.g. "1:59:30.1"
 * or "3.6" or "5:33.2"./* ww  w  .  ja v  a  2s .c om*/
 * Rolled my own because JDK 7's DateFormat class seemed
 * to require some unnatural contortions. JDK 8 has a much
 * richer library.
 *
 * @param milliseconds Time in millseconds since start of meeting
 * @return String formatted time interval string in "H:MM:SS.m" format.
 */
public static String timeToHMMSSm(long milliseconds) {
    Log.v(TAG, "timeToHMMSSm(" + milliseconds + ")");

    double seconds = (milliseconds % 60_000) / 1000.0;
    int minutes = (int) (milliseconds / 60_000) % 60;
    int hours = (int) (milliseconds / 3600_000);

    String hms;
    if (hours >= 1) {
        hms = String.format(Locale.getDefault(), "%d:%02d:%04.1f", hours, minutes, seconds);
    } else if (minutes >= 1) {
        hms = String.format(Locale.getDefault(), "%d:%04.1f", minutes, seconds);
    } else {
        hms = String.format(Locale.getDefault(), "%1.1f", seconds);
    }
    return hms;
}

From source file:Main.java

public static String getCarrier(Context ctx) {
    TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    return tm.getNetworkOperatorName().toLowerCase(Locale.getDefault());
}

From source file:Main.java

/**
 * Gets a locale for the given language code.
 *//*from  w w  w. ja  v  a 2  s .  c o  m*/
public static Locale languageLocale(String languageCode) {
    if (TextUtils.isEmpty(languageCode))
        return Locale.getDefault();

    if (languageCode.length() > NO_REGION_LANG_CODE_LEN) {
        return new Locale(languageCode.substring(0, NO_REGION_LANG_CODE_LEN),
                languageCode.substring(REGION_SUBSTRING_INDEX));
    }

    return new Locale(languageCode);
}

From source file:Main.java

public static String getTimeRemaining(long durationInMilliseconds) {
    SimpleDateFormat sdf;//from  www . ja v  a2 s.c  om
    if (durationInMilliseconds > 1000 * 60 * 60) {
        sdf = new SimpleDateFormat("HH:mm", Locale.getDefault());
    } else {
        sdf = new SimpleDateFormat("mm:ss", Locale.getDefault());
    }
    return sdf.format(new Date(durationInMilliseconds - TimeZone.getDefault().getRawOffset()));
}

From source file:Main.java

public static String getFormattedTime(Context context, Calendar time) {
    String skeleton = DateFormat.is24HourFormat(context) ? "EHm" : "Ehma";
    String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
    return (String) DateFormat.format(pattern, time);
}

From source file:Main.java

public static String getTimestamp() {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault());
    return formatter.format((new Date()).getTime());
}

From source file:Main.java

public static String stringDateToString(String format, String dateString) {
    ParsePosition position = new ParsePosition(0);
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.getDefault());
    SimpleDateFormat StringDateFormat = new SimpleDateFormat(format);
    Date dateValue = null;//  w ww  . ja  v  a  2s  .  com
    String data = "";
    try {
        dateValue = simpleDateFormat.parse(dateString, position);
        data = StringDateFormat.format(dateValue);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return data;
}

From source file:Main.java

public static String newFileName() {
    Date date = new Date();
    DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd_HH-mm-ss", Locale.getDefault());
    return dateFormat.format(date) + ".jpg";
}