Java Date Long Format getLongDateString(Date date, boolean includeTime)

Here you can find the source of getLongDateString(Date date, boolean includeTime)

Description

Returns long date string representation in localized format (e.g.

License

Open Source License

Parameter

Parameter Description
date Date to convert into string
includeTime Indicates whether to append time string or not. If true, time string will be appended in short format (e.g. 11:01)

Declaration

public static String getLongDateString(Date date, boolean includeTime) 

Method Source Code


//package com.java2s;
/*//w  ww  .  ja  va  2  s  . c om
 * $Id: DateUtils.java,v 1.4 2005/10/10 18:02:45 rbair Exp $
 *
 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
 * Santa Clara, California 95054, U.S.A. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

import java.text.DateFormat;

import java.util.Date;

public class Main {
    /**
     * Returns long date string representation in localized format (e.g.
     * February 11, 2012).
     *
     * @param date Date to convert into string
     * @param includeTime Indicates whether to append time string or not. If
     * true, time string will be appended in short format (e.g. 11:01)
     */
    public static String getLongDateString(Date date, boolean includeTime) {
        if (includeTime) {
            return getDateTimeString(date, DateFormat.LONG, DateFormat.SHORT);
        } else {
            return getDateString(date, DateFormat.LONG);
        }
    }

    /**
     * Returns date and time string representation in localized format.
     *
     * @param date Date to convert into string
     * @param dateStyle Date style format (DateFormat.SHORT, DateFormat.MEDIUM,
     * DateFormat.LONG)
     * @param timeStyle Time style format (DateFormat.SHORT, DateFormat.MEDIUM,
     * DateFormat.LONG)
     */
    public static String getDateTimeString(Date date, int dateStyle, int timeStyle) {
        if (date == null) {
            return "";
        }
        DateFormat f = DateFormat.getDateTimeInstance(dateStyle, timeStyle);
        return f.format(date);
    }

    /**
     * Returns date string representation in localized format.
     *
     * @param date Date to convert into string
     * @param dateStyle Date style format (DateFormat.SHORT, DateFormat.MEDIUM,
     * DateFormat.LONG)
     */
    public static String getDateString(Date date, int dateStyle) {
        if (date == null) {
            return "";
        }
        DateFormat f = DateFormat.getDateInstance(dateStyle);
        return f.format(date);
    }
}

Related

  1. getLongDateFormatter()
  2. getLongDateStr(Date sDate)
  3. getLongDateString(Date date)
  4. getLongDateString(Date date)
  5. getLongDateString(Date date)
  6. getLongDisplayDate(Date moment, TimeZone tz, Locale inLocale)
  7. getLongDisplayTime(long time)
  8. getLongFormatTime(java.util.Date date)
  9. getLongFromDatestamp(String datestamp)