Here you can find the source of convertDateToString(Date dateObject, String dateFormat)
Parameter | Description |
---|---|
dateObject | a parameter |
dateFormat | a parameter |
public static String convertDateToString(Date dateObject, String dateFormat)
//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; } } }