Java SQL Date Create getCurrentDate()

Here you can find the source of getCurrentDate()

Description

Get current date, format yyyy/MM/dd.

License

Apache License

Declaration

public static String getCurrentDate() 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.sql.Timestamp;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import java.util.TimeZone;

public class Main {
    public static final String DEFAULT_TIMEZONE = "Aisa/Shanghai";
    public static final String FORMAT_DATE_YYYY_MM_DD = "yyyy-MM-dd";

    /**/*from w ww. j  av a2 s . c om*/
     * Get current date, format yyyy/MM/dd.
     *
     * @return
     */
    public static String getCurrentDate() {
        return formatDate(getCurrentTimestamp());
    }

    public static String formatDate(Date iDate) {
        return formatDate(iDate, FORMAT_DATE_YYYY_MM_DD);
    }

    public static String formatDate(Date iDate, String sDatePattern) {
        if (iDate == null) {
            return null;
        }
        SimpleDateFormat oFormat = new SimpleDateFormat(sDatePattern);
        oFormat.setLenient(false);
        return oFormat.format(iDate);
    }

    public static Timestamp getCurrentTimestamp() {
        return new Timestamp(getDate().getTime());
    }

    public static Date getDate() {
        TimeZone tz = TimeZone.getTimeZone(DEFAULT_TIMEZONE);
        Calendar calendar = Calendar.getInstance(tz);
        return calendar.getTime();
    }
}

Related

  1. currentDate()
  2. getCurrDate()
  3. getCurrentDate()
  4. getCurrentDate()
  5. getCurrentDate()
  6. getCurrentDate()
  7. getCurrentDate()
  8. getCurrentDate()
  9. getCurrentDateStart()