Example usage for java.util Locale ENGLISH

List of usage examples for java.util Locale ENGLISH

Introduction

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

Prototype

Locale ENGLISH

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

Click Source Link

Document

Useful constant for language.

Usage

From source file:Main.java

/**
 * Gets the day of week out of a date./*w ww.j  a v  a 2s .  c  o  m*/
 *
 * @param dateString represents the date.
 * @return the day of week of the date.
 */
public static String dateToDayOfWeek(String dateString) {
    Date date = new Date();
    try {
        date = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.GERMAN).parse(dateString);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    DateFormat dtfmt = new SimpleDateFormat("EEE", Locale.ENGLISH);
    String dayOfWeek = dtfmt.format(date);
    return dayOfWeek;
}

From source file:Main.java

public static String camelCaseToDash(String string) {
    StringBuilder sb = new StringBuilder(2 * string.length());
    boolean prevLowerCase = false, prevIsAlpha = false;
    for (int i = 0; i < string.length(); ++i) {
        boolean nextLowerCase = i < string.length() - 1 ? Character.isLowerCase(string.charAt(i + 1)) : false;
        char c = string.charAt(i);
        if (Character.isUpperCase(c)) {
            if ((prevLowerCase || nextLowerCase) && prevIsAlpha)
                sb.append('-');
            sb.append(String.valueOf(c).toLowerCase(Locale.ENGLISH));
        } else if (c == '.') {
            sb.append('-');
        } else {//from w  ww.  ja v a 2 s . c o  m
            sb.append(c);
        }
        prevLowerCase = Character.isLowerCase(c);
        prevIsAlpha = Character.isAlphabetic(c);
    }
    return sb.toString();
}

From source file:Main.java

public static String formatDuration(long duration) {
    String strTime = "00:00";
    do {/*from w ww. j a va 2s.  co m*/
        if (duration <= 0) {
            break;
        }

        long second = duration / MISEC_UINTS_SECOND;
        if (second < SECOND_UINTS_MINUTE) {
            strTime = String.format(Locale.ENGLISH, "00:%02d", second);
            break;
        }

        if (second < SECOND_UINTS_HOUR) {
            strTime = String.format(Locale.ENGLISH, "%02d:%02d", second / MINUTE_UNINTS_HOUR,
                    second % SECOND_UINTS_MINUTE);
            break;
        }

        if (second < SECOND_UINTS_DAY) {
            strTime = String.format(Locale.ENGLISH, "%02d:%02d:%02d", second / SECOND_UINTS_HOUR,
                    (second % (SECOND_UINTS_HOUR)) / MINUTE_UNINTS_HOUR,
                    (second % (SECOND_UINTS_HOUR)) % SECOND_UINTS_MINUTE);
            break;
        }

        if (second > SECOND_UINTS_DAY) {
            strTime = second + "";
            break;
        }

    } while (false);

    return strTime;
}

From source file:Main.java

public static String convertToReadableTime(long milliseconds, boolean includeHours) {

    if (includeHours) {
        // format hh:mm:ss
        return String.format(Locale.ENGLISH, "%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(milliseconds),
                TimeUnit.MILLISECONDS.toMinutes(milliseconds) % TimeUnit.HOURS.toMinutes(1),
                TimeUnit.MILLISECONDS.toSeconds(milliseconds) % TimeUnit.MINUTES.toSeconds(1));
    } else if (TimeUnit.MILLISECONDS.toHours(milliseconds) < 1) {
        // format mm:ss
        return String.format(Locale.ENGLISH, "%02d:%02d",
                TimeUnit.MILLISECONDS.toMinutes(milliseconds) % TimeUnit.HOURS.toMinutes(1),
                TimeUnit.MILLISECONDS.toSeconds(milliseconds) % TimeUnit.MINUTES.toSeconds(1));
    } else {//from   w w  w.  j a  v a 2  s. c  o m
        return null;
    }

}

From source file:Main.java

/**
 * Try to parse input with SimpleDateFormat
 *
 * @param input input./*  w w  w.  j av  a  2  s.  c  o  m*/
 * @param format      SimpleDateFormat
 * @param setYear1700 When true the age will be not displayed in brackets
 * @return Date object if successful, otherwise null
 */
private static Date parseStringWithSimpleDateFormat(String input, String format, boolean setYear1700) {
    return parseStringWithSimpleDateFormat(input, format, setYear1700, Locale.ENGLISH);
}

From source file:Main.java

/**
 * Get the Date from String with custom format. Default format is yyyy-MM-dd
 * /*from   ww w.  jav  a  2  s.c  o m*/
 * @param dateString
 * @param dateFormat
 * @return
 * @throws ParseException
 */
public static Date getDateFromString(String dateString, String dateFormat) throws ParseException {
    SimpleDateFormat formatter;
    if (dateFormat == null) {
        formatter = yyyyMMddFormat;
    } else {
        formatter = new SimpleDateFormat(dateFormat, Locale.ENGLISH);
    }

    return formatter.parse(dateString);
}

From source file:Main.java

public static String capitalize(String input) {
    return input.toUpperCase(new Locale(Locale.ENGLISH.getLanguage(), Locale.US.getCountry()));
}

From source file:Main.java

public static String convertByteWithUnit(long b) {
    if (b > 1024 * 1024 * 1024) {
        return String.format(Locale.ENGLISH, "%.2fGB", (float) b / (1024 * 1024 * 1024));
    } else if (b > 1024 * 1024) {
        return String.format(Locale.ENGLISH, "%.2fMB", (float) b / (1024 * 1024));
    } else if (b > 1024) {
        return String.format(Locale.ENGLISH, "%.2fkB", (float) b / 1024);
    } else {/*from   w w  w . j  a v  a 2 s.c o  m*/
        return b + "byte";
    }
}

From source file:Main.java

public static Date getDateFromString(String format, String dateString) throws ParseException {
    Locale locale = Locale.ENGLISH;
    SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
    sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
    return sdf.parse(dateString);
}

From source file:Main.java

private static String encodingSpecUrlChar(char c) {
    int asciiCode = (int) c;
    String hexStr = Integer.toHexString(asciiCode).toUpperCase(Locale.ENGLISH);
    if (hexStr.length() < 2) {
        hexStr = "0" + hexStr;
    }/*ww w.  j av  a 2 s . c om*/

    String result = "%" + hexStr;
    return result;
}