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 formatDate(long date) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    return format.format(new Date(date));
}

From source file:Main.java

public static String getFormatDate(int step) {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, step);
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
    String str = sf.format(cal.getTime());
    return str;// w w w. j  ava 2  s  . c  o m
}

From source file:Main.java

public static String month(Date now) {
    SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM");
    String strDate = sdfDate.format(now);
    return strDate;
}

From source file:Main.java

public static String convertDateToString(Date date, String format) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
    return simpleDateFormat.format(date);
}

From source file:Main.java

public static int isDayorNight() {
    SimpleDateFormat sdf = new SimpleDateFormat("HH");
    String hour = sdf.format(new Date());
    int k = Integer.parseInt(hour);
    if ((k >= 0 && k < 6) || (k >= 18 && k < 24)) {
        return NIGHT;
    } else {//from ww  w .  jav a 2  s  . com
        return DAY;
    }
}

From source file:Main.java

/**
 * date format yyyy-MM-dd HH:mm:ss/*from   www  .j  a  v a 2 s . c  o m*/
 * */
public static String DateFormatTwo(Date date) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return sdf.format(date);
}

From source file:Main.java

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

From source file:Main.java

public static String setTimeDateDd(long time) {
    SimpleDateFormat format = new SimpleDateFormat("MM-dd");
    String timeDate = format.format(new Date(time));
    return timeDate;
}

From source file:Main.java

public static String getPhotoFileName() {
    Date date = new Date(System.currentTimeMillis());
    SimpleDateFormat sdf = new SimpleDateFormat("'PNG'_yyyyMMdd_HHmmss");
    return sdf.format(date) + ".png";
}

From source file:Main.java

public static boolean equalsYear(Date a, Date b) {
    SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy", locale);
    return yearFormat.format(a).equals(yearFormat.format(b));
}