Example usage for java.text SimpleDateFormat format

List of usage examples for java.text SimpleDateFormat format

Introduction

In this page you can find the example usage for java.text SimpleDateFormat 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 DateToStr(Date date) {

    SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
    String str = format.format(date);
    return str;/* w  w w .  j  a v a  2 s. c om*/
}

From source file:Main.java

public static String getDate() {
    Date date = new Date(System.currentTimeMillis());
    String strs = "";
    try {/*  ww  w.j  a va  2s. co  m*/
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        strs = sdf.format(date);
    } catch (Exception e) {
        e.printStackTrace();
    }
    //      return "20140321";
    return strs;
}

From source file:Main.java

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

From source file:Main.java

public static String dateToStringAgenda(Date date) {
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM - hh:mm a");
    String sDate = sdf.format(date);
    return sDate;
}

From source file:Main.java

public static String getDate() {
    Date date = new Date(System.currentTimeMillis());
    String strs = "";
    try {//from w ww .j a v a2  s .  c o m
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        strs = sdf.format(date);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return strs;
}

From source file:Main.java

public static String getSpecialTime(Date specialDate, String pattern) {
    SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, Locale.CHINA);
    return dateFormat.format(specialDate);
}

From source file:Main.java

public static String convertDateToCalendarStr(Date date) {
    SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMddHHmmssSS");
    String dateText = df2.format(date);
    return dateText;
}

From source file:Main.java

public static String generateUniqueID() {
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyyHHmmss", Locale.US);
    return sdf.format(cal.getTime());

}

From source file:Main.java

/**
 * MM-dd HH:mm:ss// w  w  w  .jav a  2 s. c o  m
 */
@SuppressLint("SimpleDateFormat")
public static String getNowMDHMSTime() {
    SimpleDateFormat mDateFormat = new SimpleDateFormat("MM-dd HH:mm:ss");
    return mDateFormat.format(new Date());
}

From source file:Main.java

public static String getSanShengDate(long time) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    String dateString = formatter.format(time);
    return dateString;
}