Java yyyy format(Date date)

Here you can find the source of format(Date date)

Description

Method for formatting a Date into a String with the default format (dd/MM/yyyy)

License

Open Source License

Parameter

Parameter Description
date Date to be formatted

Return

resultant String object

Declaration

public static String format(Date date) 

Method Source Code

//package com.java2s;
/*//from   ww  w  . j  a v a 2 s .c o m
Copyright 2012 Juan Mart?n Runge
    
jmrunge@gmail.com
http://www.zirsi.com.ar
    
This file is part of ZirUtils.
    
ZirUtils is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
ZirUtils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with ZirUtils.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**
     * Method for formatting a Date into a String with the default format (dd/MM/yyyy)
     * 
     * @param date Date to be formatted
     * @return resultant String object
     * @see java.text.SimpleDateFormat
     */
    public static String format(Date date) {
        return format(date, null);
    }

    /**
     * Method for formatting a Date into a String with the specified format
     * 
     * @param date Date to be formatted
     * @param format the format
     * @return resultant String object
     * @see java.text.SimpleDateFormat
     */
    public static String format(Date date, String format) {
        if (date == null)
            return null;
        if (format == null)
            format = "dd/MM/yyyy";
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }
}

Related

  1. format()
  2. format(Date aTs_Datetime)
  3. format(Date date)
  4. format(Date date)
  5. format(Date date)
  6. format(Date date)