Java SQL Date Create getDateFormat(java.util.Date date)

Here you can find the source of getDateFormat(java.util.Date date)

Description

getting a date string like 'yyyy-MM-dd' from a java.util.Date or java.sql.Date

License

Open Source License

Parameter

Parameter Description
date a java.util.Date or java.sql.Date

Return

a string like 'yyyy-MM-dd'

Declaration

public static String getDateFormat(java.util.Date date) 

Method Source Code


//package com.java2s;

import java.text.SimpleDateFormat;

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

    /**//from  w  w w.  j av a 2 s.c o m
     * 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);
    }

    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. getDataMaior(java.sql.Date data1, java.sql.Date data2)
  2. getDateAfter(Date date, Integer after)
  3. getDateAfter(Date date, long offset)
  4. getDateAsString(int month, int date, int year)
  5. getDateFormat()
  6. getDateString(String date)
  7. getDateString(String pattern)
  8. getDateString2()
  9. getDay(Date date)