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 formatDate(Date date, String fmt, Locale locale) {
    DateFormat format = new SimpleDateFormat(fmt, locale);

    return format.format(date);
}

From source file:Main.java

public static String dateFormat(Date date, int format) {
    DateFormat dateFormat1 = DateFormat.getDateInstance(format);
    return dateFormat1.format(date);
}

From source file:Main.java

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

From source file:Main.java

public static String toDate(Date date) {
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
    return dateFormat.format(date);
}

From source file:Main.java

/**
 * yyyy-MM-dd//  w  w  w  .j a v a 2s .c om
 * 
 * @param date
 * @return
 */
public static String dateToOtherString(Date date) {
    DateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
    return dateformat.format(date);
}

From source file:Main.java

/**
 * * Dates the DateTime into an XML schema date time.
 * //from ww  w .java2s  . co  m
 * @param date
 *            the date
 * @return String representation of DateTime.
 */
protected static String dateTimeToXSDateTime(Date date) {
    String format = "yyyy-MM-dd'T'HH:mm:ss'Z'";
    DateFormat utcFormatter = new SimpleDateFormat(format);
    return utcFormatter.format(date);
}

From source file:Main.java

/**
 * * Convert DateTime to XML Schema date.
 * /* w w  w.ja  v  a 2  s .  c  o m*/
 * @param date
 *            the date
 * @return String representation of DateTime.
 */
static String dateTimeToXSDate(Date date) {
    String format = "yyyy-MM-dd'Z'";
    DateFormat utcFormatter = new SimpleDateFormat(format);
    return utcFormatter.format(date);
}

From source file:Main.java

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

From source file:Main.java

public static String getStringFromDateTime(Date nowdate) {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd  HH:mm");
    String sdt = df.format(new Date(System.currentTimeMillis()));
    return sdt;//www  .j  a  va  2s .c  o m
}

From source file:Main.java

public static String getDateFromCal(String pattern, Calendar cal) {
    DateFormat df = new SimpleDateFormat(pattern, Locale.getDefault());
    return df.format(cal.getTime());
}