Java Date Now getCurrentDateFormat()

Here you can find the source of getCurrentDateFormat()

Description

get current date

License

Open Source License

Return

the string of current date

Declaration

public static String getCurrentDateFormat() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**/*from  ww w  .j a  v a 2  s.c  o  m*/
     * default date format pattern
     */
    public final static String DATE_FORMAT = "yyyy-MM-dd";

    /**
     * get current date
     *
     * @return the string of current date
     */
    public static String getCurrentDateFormat() {
        return formatDate(new Date());
    }

    /**
     * format date with the default pattern
     *
     * @param date the date that want to format to string
     * @return the formated date
     */
    public static String formatDate(Date date) {
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        return format.format(date);
    }

    /**
     * format date with the given pattern
     *
     * @param date the date that want to format to string
     * @param pattern the formated pattern
     * @return the formated date
     */
    public static String formatDate(Date date, String pattern) {
        if (date == null) {
            return null;
        }
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        return format.format(date);
    }
}

Related

  1. getCurrentDateAsString()
  2. getCurrentDateAsString(DateFormat df)
  3. getCurrentDateAsString(String timestampFormat)
  4. getCurrentDateByString(String datePattern)
  5. getCurrentDateDBFormat()
  6. getCurrentDateFormated()
  7. getCurrentDateInMillis()
  8. getCurrentDateInSqlFormat()
  9. getCurrentDateINYYYY_MM_DD()