Here you can find the source of format(final Date date, final String format)
Parameter | Description |
---|---|
date | The date to format. |
format | The date format to use. |
public static String format(final Date date, final String format)
//package com.java2s; /**// www . j av a 2 s . co m * Copyright 2005-2008 Noelios Technologies. * * The contents of this file are subject to the terms of the following open * source licenses: LGPL 3.0 or LGPL 2.1 or CDDL 1.0 (the "Licenses"). You can * select the license that you prefer but you may not use this file except in * compliance with one of these Licenses. * * You can obtain a copy of the LGPL 3.0 license at * http://www.gnu.org/licenses/lgpl-3.0.html * * You can obtain a copy of the LGPL 2.1 license at * http://www.gnu.org/licenses/lgpl-2.1.html * * You can obtain a copy of the CDDL 1.0 license at * http://www.sun.com/cddl/cddl.html * * See the Licenses for the specific language governing permissions and * limitations under the Licenses. * * Alternatively, you can obtain a royaltee free commercial license with less * limitations, transferable or non-transferable, directly at * http://www.noelios.com/products/restlet-engine * * Restlet is a registered trademark of Noelios Technologies. */ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; public class Main { /** Remember the often used GMT time zone. */ private static final TimeZone TIMEZONE_GMT = TimeZone.getTimeZone("GMT"); /** * Formats a Date according to the first format in the array. * * @param date * The date to format. * @param format * The date format to use. * @return The formatted date. */ public static String format(final Date date, final String format) { if (date == null) { throw new IllegalArgumentException("Date is null"); } final SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.US); formatter.setTimeZone(TIMEZONE_GMT); return formatter.format(date); } }