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

public static String getLocalizedAssetPath(AssetManager assetManager, String pathTemplate) {
    String path = String.format(Locale.US, pathTemplate, "-" + Locale.getDefault().getLanguage().toLowerCase());

    try {/*from   w w w  .j  a v  a 2  s  . c o m*/
        InputStream is = assetManager.open(path);
        is.close();
    } catch (Exception ex) {
        path = String.format(Locale.US, pathTemplate, "");
    }

    return "file:///android_asset/" + path;
}

From source file:Main.java

public static String cmsToInches(String cmsAsString) {
    try {/*from   w  w w  .j  av  a 2 s  . co m*/
        float cms = Float.parseFloat(cmsAsString);
        float inches = cms / CMS_PER_INCH;
        return String.format(Locale.US, "%.1f \"", inches);
    } catch (NumberFormatException e) {
        /*- not a number, text is shown without parsing it */
        return cmsAsString;
    }
}

From source file:Main.java

static String getFormatTime(long timestamp) {
    try {/*from w  w w. java  2  s .c  o m*/
        Date e = new Date(timestamp);
        SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
        String result = localSimpleDateFormat.format(e);
        return result;
    } catch (Exception var5) {
        return "";
    }
}

From source file:Main.java

public static String formatDate(Calendar calendar) {
    String format = "yyyy-MM-dd HH:mm:ss";
    SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US);
    return sdf.format(calendar.getTime());
}

From source file:Main.java

static String getFormatTime(long timestamp) {
    try {//w w  w .  ja  va2  s  . co m
        Date date = new Date(timestamp);
        SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
        String result = localSimpleDateFormat.format(date);
        return result;
    } catch (Exception e) {
        return "";
    }
}

From source file:Main.java

public static String getCurrentDate() {
    String date = null;/*from ww w . ja va  2s  .  c om*/
    Calendar cal = Calendar.getInstance();
    DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
    date = dfm.format(cal.getTime());
    return date;
}

From source file:Main.java

public static String fmtDate(Date date) {
    if (null == date) {
        return null;
    }//  w  w  w .j a  v  a  2  s .c  o  m
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
        return sdf.format(date);
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

private static String fmtDate(Date date) {
    if (null == date) {
        return null;
    }// ww  w.ja  v a 2 s. c  o  m
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
        return sdf.format(date);
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

public static String formatPercent(long completed, long total) {
    if (completed <= 0 || total <= 0) {
        return "0.0%";
    }//from   www. j a v a2 s  .c  o m
    final float c = completed;
    final float t = total;
    try {
        return String.format(Locale.US, "%.1f%%", c / t * 100);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "0.0%";
}

From source file:Main.java

public static Calendar getDateFromString(String string, String format) {
    Calendar calendar = null;//from   w ww . j a va2  s .co m

    SimpleDateFormat form = new SimpleDateFormat(format, Locale.US);
    Date date = null;

    try {
        date = form.parse(string);

        calendar = Calendar.getInstance();
        calendar.setTime(date);
    } catch (java.text.ParseException e) {
    }

    return calendar;
}