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 parseDateToStr(Date date, String fmt) {
    DateFormat dateFormat = new SimpleDateFormat(fmt, Locale.SIMPLIFIED_CHINESE);
    return dateFormat.format(date);
}

From source file:elaborate.editor.backend.AnnotationMarkerScrubber.java

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

From source file:Main.java

public static String dateToString(Date date) {
    if (date == null) {
        return null;
    }//ww w  .j  a v a 2  s  .  c o m
    try {
        DateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateformat.format(date);
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

public static String createDatestring(long timestamp) {
    if (timestamp == 0) {
        return "";
    }/* w ww. j av  a 2 s.  c om*/
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
    return df.format(new Date(timestamp));
}

From source file:Main.java

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

From source file:Main.java

public static String convertToDateSimple(Date date) {
    DateFormat format = new SimpleDateFormat("EEE, MMM. d '\n'h:mm a", Locale.getDefault());
    return format.format(date);
}

From source file:Main.java

public static String getDate() {
    Date date = new Date();
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());

    return format.format(date);
}

From source file:Main.java

public static String getPrettyDateTime(Calendar date) {
    DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT);
    return dateTimeFormat.format(date.getTime());
}

From source file:Main.java

/**
 * Write a {@link Calendar} value into XML output.
 *
 * @param value/*from   w  w w .j  a  v  a2 s  .c  o  m*/
 * value to write
 *
 * @return
 * XML string
 *
 * @throws IllegalArgumentException
 * if a validation error occured
 */
public static String printDate(Calendar value) {
    //return (value!=null)? DatatypeConverter.printDate( value ): null;
    if (value == null)
        return null;
    DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    return formatter.format(value.getTime());
}

From source file:Main.java

/**
 * Converts long to date/*from   ww w  .  ja  v  a  2 s.  c om*/
 * 
 * @param timeStamp
 *            date
 * @return date converts the date in required format
 */
public static String convertToDate(long timeStamp) {
    if (timeStamp <= 0) {
        return "";
    }
    Date date = new Date(timeStamp);
    DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    String strDate = formatter.format(date);
    return strDate;
}