Java SQL Date Create currentDate()

Here you can find the source of currentDate()

Description

gets current time's string format like "yyyy-MM-dd"

License

Open Source License

Declaration

public static String currentDate() 

Method Source Code


//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /** The date format string:(yyyy-MM-dd) */
    public static final String DATE_FORMAT_STR = "yyyy-MM-dd";

    /**/*from   ww w.  jav  a2  s  . com*/
     * gets current time's string format like "yyyy-MM-dd"
     * 
     * @return
     */
    public static String currentDate() {
        return getDateFormat(now());
    }

    /**
     * getting a date string like 'yyyy-MM-dd' from a java.util.Date or java.sql.Date
     * 
     * @param date a java.util.Date or java.sql.Date
     * @return a string like 'yyyy-MM-dd'
     */
    public static String getDateFormat(java.util.Date date) {
        return getFormat(date, DATE_FORMAT_STR);
    }

    /**
     * Returns the current datetime.
     * 
     * @return the current datetime.
     */
    public static Date now() {
        return new Date(System.currentTimeMillis());
    }

    public static String getFormat(java.util.Date date, String parseFormat) {
        if (null == date) {
            return null;
        }
        if (null == parseFormat || "".equalsIgnoreCase(parseFormat)) {
            return date.toString();
        }
        return new SimpleDateFormat(parseFormat).format(date);
    }
}

Related

  1. createSqlDate(String dateStr)
  2. createStreamingStatement(Connection conn, boolean update)
  3. createUpdateStatement(Connection conn, String databaseName, String[] fieldsToUpdate, String[] selectionFields)
  4. currentDate()
  5. currentDate()
  6. getCurrDate()
  7. getCurrentDate()
  8. getCurrentDate()
  9. getCurrentDate()