Here you can find the source of formatDate(Date date, String format)
Parameter | Description |
---|---|
date | Date to format. |
format | Format of result string. |
public static String formatDate(Date date, String format)
//package com.java2s; /**/*from w ww . java 2 s . c o m*/ * Copyright ? Microsoft Open Technologies, Inc. * * All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT. * * See the Apache License, Version 2.0 for the specific language * governing permissions and limitations under the License. */ import java.text.SimpleDateFormat; import java.util.Date; public class Main { /** * Default time date format. */ private static final String DEFAULT_TIME_DATE_FORMAT = "yyyy'-'MM'-'dd'T'HH':'mm':'ssZ"; /** * Formats date to the string with default time date format. * * @param time Date to format. * * @return Result string. */ public static String formatDate(Date time) { SimpleDateFormat dateformat = new SimpleDateFormat( DEFAULT_TIME_DATE_FORMAT); return dateformat.format(time); } /** * Formats date to the string with specific time date format. * * @param date Date to format. * @param format Format of result string. * * @return Formatted date string. */ public static String formatDate(Date date, String format) { return new SimpleDateFormat(format).format(date); } }