Here you can find the source of formatDate(Date date, String pattern)
Parameter | Description |
---|---|
date | the date to be formatted |
pattern | the pattern describing the date and time format |
public static String formatDate(Date date, String pattern)
//package com.java2s; /*/*w ww . j a v a 2 s .com*/ * Copyright (C) 2011-2012 Inaki Ortiz de Landaluce Saiz * * 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 Lesser General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/> */ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { /** * Formats a date into a date/time string using the default TimeZone for * this host. * * @param date * the date to be formatted * @param pattern * the pattern describing the date and time format * @return the formatted time string */ public static String formatDate(Date date, String pattern) { return formatDate(date, pattern, TimeZone.getDefault()); } /** * Formats a date into a date/time string * * @param date * the date to be formatted * @param pattern * the pattern describing the date and time format * @param zone * the time zone * @return the formatted time string */ public static String formatDate(Date date, String pattern, TimeZone zone) { DateFormat dfmt = new SimpleDateFormat(pattern); dfmt.setTimeZone(zone); return dfmt.format(date); } }