Example usage for java.text DateFormat format

List of usage examples for java.text DateFormat format

Introduction

In this page you can find the example usage for java.text DateFormat format.

Prototype

public final String format(Date date) 

Source Link

Document

Formats a Date into a date-time string.

Usage

From source file:Main.java

public static String getYear(long time) {
    DateFormat dateFormat = new SimpleDateFormat("yyyy", Locale.CHINA);
    return dateFormat.format(time);
}

From source file:Main.java

public static String converteDataParaPadraoBanco(Date date) {
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return dateFormat.format(date);
}

From source file:Main.java

public static String formatTime(String date, String format, String destFormat) {
    try {/*from  w w w .j av  a  2s . com*/
        DateFormat format1 = new SimpleDateFormat(format);
        DateFormat format2 = new SimpleDateFormat(destFormat);
        return format2.format(format1.parse(date));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static String converteDataParaPadraoBrasil(Date date) {
    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    return dateFormat.format(date);
}

From source file:Main.java

public static String getCurrentServerTime(long time) {
    DateFormat dateFormat = new SimpleDateFormat("HH:mm", Locale.CHINA);
    return dateFormat.format(time);
}

From source file:Util.java

public static String getStringFromDate(Date date) throws ParseException {
    DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    return formatter.format(date);
}

From source file:Main.java

public static String getPrettyDate(int year, int month, int day) {
    Calendar c = new GregorianCalendar(year, month, day);
    DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG);
    return dateFormat.format(c.getTime());
}

From source file:Main.java

public static String getTimeInStringFormat(Date date) {
    DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    return dateFormat.format(date);
}

From source file:Main.java

public static String getDateString(String format, Date date) {
    DateFormat dateFormat = new SimpleDateFormat(format);
    String dateString = dateFormat.format(date);
    return dateString;
}

From source file:Main.java

public static String getCurrentDate() {
    String date = null;// ww w. j  av  a2s . co m
    Calendar cal = Calendar.getInstance();
    DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
    date = dfm.format(cal.getTime());
    return date;
}