Example usage for java.util Locale US

List of usage examples for java.util Locale US

Introduction

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

Prototype

Locale US

To view the source code for java.util Locale US.

Click Source Link

Document

Useful constant for country.

Usage

From source file:Main.java

/**
 * Returns ordinal form of the day of month.
 * 1 = 1st/* www .j a  va 2 s . c o  m*/
 * 2 = 2nd
 *
 * @param date
 * @return ordinal day of month
 */
public static String getOrdinalDayOfMonth(Date date) {
    Calendar cal = Calendar.getInstance(Locale.US);
    cal.setTime(date);
    return getOrdinalDayOfMonth(cal);
}

From source file:Main.java

/**
 * Returns the given amount of meters in rounded yards if the default locale
 * is US, in rounded meters otherwise.// www.j  av a  2 s. c  o  m
 * @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

private static int normalizeYear(int year) {
    if (year < 100 && year >= 0) {
        Calendar now = Calendar.getInstance();
        String currentYear = String.valueOf(now.get(Calendar.YEAR));
        String prefix = currentYear.substring(0, currentYear.length() - 2);
        year = Integer.parseInt(String.format(Locale.US, "%s%02d", prefix, year));
    }/*from  www . j a va 2 s. c  o m*/
    return year;
}

From source file:net.portalblockz.portalbot.Utils.java

public static String getDate() {
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
    sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
    return sdf.format(calendar.getTime());
}

From source file:com.infullmobile.jenkins.plugin.restrictedregister.util.AppUrls.java

@Nonnull
public static String buildSignInUrl() throws InvalidUriException {
    String ret = null;// ww  w  .  j  a  va 2  s . c o  m
    final String path = String.format(Locale.US, FORMAT_LOGIN_PATH,
            PluginModule.getDefault().getJenkinsDescriptor().getLoginURI());
    try {
        final URIBuilder builder = new URIBuilder(getRootURL());
        builder.setPath(path);
        final URI uri = builder.build();
        ret = uri.toURL().toExternalForm();
    } catch (URISyntaxException | MalformedURLException e) {
        onError(e.getLocalizedMessage());
    }
    return ret;
}

From source file:Main.java

/**
 * Converts a string representation of a date to that date
 *
 * @param dateString The string to parse
 * @param format     The format to parse the string with
 * @return The date, or null//from w w  w . jav  a2 s. co m
 */
public static Date stringToDate(String dateString, String format) {
    if (dateString == null) {
        return null;
    }
    SimpleDateFormat df = new SimpleDateFormat(format, Locale.US);
    try {
        return df.parse(dateString);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static String convertLocationTime(final long time) {
    final long age;

    age = System.currentTimeMillis() - time; // in ms
    if (age < 1000) // < 1s
        return "< 1s";
    else/*from   w  w w . j  a  v  a2  s  . c  o m*/
        return String.format(Locale.US, "%d s", age / 1000);
}

From source file:Main.java

/**
 * Capitalize make the first letter of the word be upper case.
 * //from   w  w w  . j ava2  s .c o  m
 * @param string
 *            The word to capitalize.
 * @return The word after capitalize.
 */
public static String capitalize(String string) {
    if (!TextUtils.isEmpty(string)) {
        return string.substring(0, 1).toUpperCase(Locale.US) + string.substring(1);
    }
    return string == null ? null : "";
}

From source file:Main.java

/**
 * Read the first line of "/proc/cpuinfo" file, and check if it is 64 bit.
 */// w w w . j av a 2  s . c o m
public static boolean isCPUInfo64() {
    File cpuInfo = new File(PROC_CPU_INFO_PATH);
    if (cpuInfo != null && cpuInfo.exists()) {
        InputStream inputStream = null;
        BufferedReader bufferedReader = null;
        try {
            inputStream = new FileInputStream(cpuInfo);
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream), 512);
            String line = bufferedReader.readLine();
            if (line != null && line.length() > 0 && line.toLowerCase(Locale.US).contains("arch64")) {
                if (LOGENABLE) {
                    //                        Log.d("###############isCPUInfo64()", PROC_CPU_INFO_PATH + " contains is arch64");
                }
                return true;
            } else {
                if (LOGENABLE) {
                    //                        Log.d("###############isCPUInfo64()", PROC_CPU_INFO_PATH + " is not arch64");
                }
            }
        } catch (Throwable t) {
            if (LOGENABLE) {
                //                    Log.d("###############isCPUInfo64()","read " + PROC_CPU_INFO_PATH + " error = " + t.toString());
            }
        } finally {
            try {
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            try {
                if (inputStream != null) {
                    inputStream.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return false;
}

From source file:Main.java

public static String getAppVer(Context context, String format) {
    if (context == null || TextUtils.isEmpty(format)) {
        return "";
    }/*w  w  w.  j a v  a  2  s  .c o  m*/

    try {
        PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return String.format(Locale.US, format, packageInfo.versionName, packageInfo.versionCode);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return "";
}