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 getCurrentTime() {

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return format.format(new Date());
}

From source file:Main.java

public static String getMonthOfYearString(int month) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MONTH, month - 1);
    SimpleDateFormat format = new SimpleDateFormat("MMM", Locale.US);
    return format.format(calendar.getTime());
}

From source file:Main.java

public static String getStringTime() {
    Date nowTime = new Date();
    System.out.println(nowTime);// ww w. j  a  v a2s  .c o  m
    SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return time.format(nowTime);
}

From source file:com.heren.turtle.server.utils.SampleDateUtils.java

public static String addDay(String time, int day) {
    Date date = getDate(time, SAMPLE_DATE);
    Date addDate = addDays(date, day);
    SimpleDateFormat format = new SimpleDateFormat(SAMPLE_DATE);
    return format.format(addDate);
}

From source file:Main.java

public static int getMonth() {
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat monthSdf = new SimpleDateFormat("MM");
    String monthString = monthSdf.format(calendar.getTime());
    return Integer.parseInt(monthString);
}

From source file:Main.java

/**
 * Parse a date to string of format HH:mm
 * @param date/*from w  ww  .  j  a v a  2s .  co m*/
 * @return
 */
public static String date2HHmm(java.util.Date date) {
    if (date == null)
        return null;
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
    String result = sdf.format(date);
    return result;
}

From source file:Main.java

@SuppressLint("SimpleDateFormat")
public static String getCurrentTime() {
    Date date = new Date(System.currentTimeMillis());
    SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd mm:ss");
    return dateFormat.format(date);
}

From source file:Main.java

public static String getTodaysTime() {
    SimpleDateFormat formater = new SimpleDateFormat(sqlTimeFormate);
    return formater.format(new Date());
}

From source file:Main.java

public static String parseTime(String date) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(Long.parseLong(date));
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    return sdf.format(c.getTime());

}

From source file:Main.java

public static String getYearFromDate(Date date) {

    Calendar c = Calendar.getInstance();
    c.setTime(date);//  ww w.  jav  a  2 s.  c  om
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
    String s = formatter.format(c.getTime());

    return s;
}