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 formatMilliseconds(long durationInMillis) {
    Date date = new Date(durationInMillis);
    DateFormat formatter = new SimpleDateFormat("mm:ss");
    return formatter.format(date);
}

From source file:Main.java

public static String getDateTimeForStr(Date date) {
    DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
    return df.format(date);
}

From source file:Main.java

public static String parseStringToDate(Date inputDate, String datePattern) {
    DateFormat dateFormat = new SimpleDateFormat(datePattern);
    return dateFormat.format(inputDate);
}

From source file:Main.java

/**
 * @param date//from w  ww  .  j  ava 2  s.c o  m
 * @return
 */
public static String getFormattedDateString(Date date, String format) {
    DateFormat dateFormat = new SimpleDateFormat(format);
    return dateFormat.format(date);
}

From source file:Util.java

public static String getTimeFromDate(Date date) throws ParseException {
    DateFormat formatter = new SimpleDateFormat("HH:mm:ss.SSS");
    return formatter.format(date);
}

From source file:Main.java

public static String dateToString(Date date, String format) {
    DateFormat df = new SimpleDateFormat(format, Locale.US);
    return df.format(date);
}

From source file:Main.java

public static String getDateFormat(long time, DateFormat df) {
    Date d = new Date(time);
    return df.format(d);
}

From source file:Main.java

/**
 * Get current date and time as a string. Used for naming backup files.
 *//* ww w .j a v  a2  s.co m*/
public static String getDateForExport() {
    DateFormat df = new SimpleDateFormat("yyMMdd-HHmm");
    return df.format(new Date());
}

From source file:Main.java

public static String getNowTime() {
    Date now = new Date();
    DateFormat df = DateFormat.getDateTimeInstance();
    String nowtime = df.format(now);
    return nowtime;
}

From source file:Main.java

/**
 * @param date/*from  ww  w  . ja  v a 2  s  . co  m*/
 * @return
 */
public static String convertDateToString(Date date) {

    String dateStr = null;
    DateFormat formatter = new SimpleDateFormat();
    dateStr = formatter.format(date);
    return dateStr;
}