Java Hour Format formattedDate(java.util.Date date, String formatString)

Here you can find the source of formattedDate(java.util.Date date, String formatString)

Description

Formats the System date in the order determined by the formatString

License

Open Source License

Parameter

Parameter Description
date The System Date
formatString The desired format for writing out the date

Return

String The formatted date

Declaration

public static String formattedDate(java.util.Date date, String formatString) 

Method Source Code

//package com.java2s;
/**/*from  w ww  .  j  a  v a 2  s . c o  m*/
 * Title: Utilities
 * Description: Utilities for string manipulation and other convenience methods
 * Copyright: Copyright (c) 2003-2014
 * 
 * <p>
 * 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 2 of the License, or (at your option) any later
 * version.
 * </p>
 * <p>
 * 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.
 * </p>
 * <p>
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 * </p>
 * 
 * @author David Read
 */

import java.text.SimpleDateFormat;

import java.util.Map;

public class Main {
    /**
     * Map used for storing date formats for formattedDate() methods
     */
    private static Map<String, SimpleDateFormat> formats;

    /**
     * Formats the System date to appear as MM/dd/yyyy HH:mm:ss.SSS
     * 
     * @param date
     *          The system date that needs to be formatted
     * 
     * @return String The formatted date
     */
    public static String formattedDate(java.util.Date date) {
        return formattedDate(date, "MM/dd/yyyy HH:mm:ss.SSS");
    }

    /**
     * Formats the System date in the order determined by the formatString
     * 
     * @param date
     *          The System Date
     * @param formatString
     *          The desired format for writing out the date
     * 
     * @return String The formatted date
     */
    public static String formattedDate(java.util.Date date, String formatString) {
        SimpleDateFormat format;

        format = (SimpleDateFormat) formats.get(formatString);
        if (format == null) {
            format = new SimpleDateFormat(formatString);
            formats.put(formatString, format);
        }

        return format.format(date);
    }
}

Related

  1. formatStringTime(String dateTime)
  2. formatStringTimeToLong(String timeLine)
  3. formatStrToDate(String strDate, int format)
  4. formatStrToDate(String value, String pattern)
  5. formattedDate()
  6. formattedDateToDate(String str)
  7. formattedStringToDate(String date)
  8. formattedTime(long epochTime)
  9. formattedTimeForFilenames()