Here you can find the source of formatDate(Date date, String datePattern)
Parameter | Description |
---|---|
date | specified date |
datePattern | specified date pattern |
public static String formatDate(Date date, String datePattern)
//package com.java2s; /*/* w w w . j a v a2 s . c om*/ * File: $RCSfile$ * * Copyright (c) 2005 Wincor Nixdorf International GmbH, * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany * All Rights Reserved. * * This software is the confidential and proprietary information * of Wincor Nixdorf ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered * into with Wincor Nixdorf. */ import java.util.Date; import java.text.DateFormat; import java.text.SimpleDateFormat; public class Main { /** * Format date with specified pattern yyyy-MM-dd * * @param date specified date * @param datePattern specified date pattern * @return string of date with @param datePattern */ public static String formatDate(Date date, String datePattern) { String ret = null; try { DateFormat dateFormat = new SimpleDateFormat(datePattern); ret = dateFormat.format(date); } catch (Exception e) { e.printStackTrace(); } return ret; } /** * Format date with default pattern yyyy-MM-dd * * @param date specified date * @return string of date with default pattern */ public static String formatDate(Date date) { return formatDate(date, "yyyy-MM-dd"); } }