Java Date Format convertDateToString(Date dateObject, String dateFormat)

Here you can find the source of convertDateToString(Date dateObject, String dateFormat)

Description

Method to convert the Date to String, Format of date to be specified.

License

Open Source License

Parameter

Parameter Description
dateObject a parameter
dateFormat a parameter

Declaration

public static String convertDateToString(Date dateObject, String dateFormat) 

Method Source Code

//package com.java2s;
/**/* ww w. j  a va2s  .  c o  m*/
 *   theMovieDb-V3-API
 *   Copyright (C) 2012  Amith GC
 *   
 *   This program 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.
 *   
 *   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *   @author Amith GC
 */

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

public class Main {
    /**
     * Method to convert the Date to String, Format of date to be specified.
     * @param dateObject
     * @param dateFormat
     * @return
     */
    public static String convertDateToString(Date dateObject, String dateFormat) {
        if (dateObject == null || isStringBlank(dateFormat)) {
            return null;
        }
        SimpleDateFormat dateFormatter = new SimpleDateFormat(dateFormat);
        StringBuilder nowYYYYMMDD = new StringBuilder(dateFormatter.format(dateObject));
        return nowYYYYMMDD.toString();
    }

    /**
     * Method to Validate the String
     * @param string
     * @return
     */
    public static boolean isStringBlank(String string) {
        if (string == null || string.isEmpty()) {
            return true;
        } else {
            return false;
        }
    }
}

Related

  1. convertDateToString(Date date, String dateFormat)
  2. convertDateToString(Date date, String format)
  3. convertDateToString(Date date, String pattern)
  4. convertDateToString(Date date, String pattern)
  5. convertDateToString(Date date, String patternString, Locale locale)
  6. convertDateToStringByFormat(Date date)
  7. convertDateToStringT(final Date date)
  8. convertDateToStringUI(Date data)
  9. convertDateToText(Date date)