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

private static String getUnits(int amount, String unitName, String unitNamePlural) {
    if (amount == 1)
        return String.format("1 %s", unitName);
    return String.format(Locale.getDefault(), "%d %s", amount, unitNamePlural);
}

From source file:Main.java

@SuppressLint("SimpleDateFormat")
public static String dateToString(long date) {
    String format, language;/* www  .jav  a 2s . c  o  m*/
    language = Locale.getDefault().getISO3Language();
    if (language.equals("spa")) {
        format = "dd/MM/yyyy HH:mm:ss";
    } else {
        format = "EEE, MMM d, yyyy HH:mm:ss";
    }
    SimpleDateFormat sdf = new java.text.SimpleDateFormat(format);
    String fecha = sdf.format(date * 1000);
    return fecha;
}

From source file:Main.java

public static long getDateAsHeaderId(long milliseconds) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("ddMMyyyy", Locale.getDefault());
    return Long.parseLong(dateFormat.format(new Date(milliseconds)));
}

From source file:Main.java

public static String getThisYearBirthDateString(final Date birthday) {
    Date now = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy", Locale.getDefault());
    String y = sdf.format(now);/*from ww  w  .j  a va2 s .  co  m*/
    sdf = new SimpleDateFormat("M-d", Locale.getDefault());
    String md = sdf.format(birthday);
    String ymd = y + "-" + md;

    return ymd;
}

From source file:Main.java

public static long getTimeInMills(String dateStr) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
    Date date = sdf.parse(dateStr);
    return date.getTime();
}

From source file:Main.java

public static String getTimeDisplay(Calendar cal) {

    SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm aa", Locale.getDefault());
    return dateFormat.format(cal.getTime());
}

From source file:Main.java

public static String toYYYYMMDDHHMMSS(Calendar source) {
    if (source != null) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        return format.format(source.getTime());
    }/*  w w w .j a  v  a 2  s  . c  om*/
    return null;
}

From source file:Main.java

public static String convertTime(long time) {
    Date date = new Date(time);
    Format format = new SimpleDateFormat("HH:mm:ss dd.MM.yyyy", Locale.getDefault());
    return format.format(date);
}

From source file:Main.java

public static Date getDateTime(String dateTime) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.getDefault());
    Date date = null;//from   w  w w . ja  v a 2  s  .  c  om
    try {
        date = dateFormat.parse(dateTime);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return date;
}

From source file:Main.java

public static String format(Calendar c, String format) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.getDefault());
    return simpleDateFormat.format(c.getTime());
}