Java Day getDayNameForDate(java.util.Date dt, boolean fullname)

Here you can find the source of getDayNameForDate(java.util.Date dt, boolean fullname)

Description

Gets the name of a day based on a date and current locale.

License

Open Source License

Parameter

Parameter Description
dt The date.
fullname Fetch complete day's name or the short one. <p>

Return

A string with the name of the day.

Declaration

public static String getDayNameForDate(java.util.Date dt, boolean fullname) 

Method Source Code

//package com.java2s;
/*/* ww  w .  j a va2  s. c o  m*/
 * DateHelper.java
 *
 * Copyright (c) 2004-2011 Gregory Kotsaftis
 * gregkotsaftis@yahoo.com
 * http://zeus-jscl.sourceforge.net/
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

import java.text.SimpleDateFormat;

public class Main {
    /**
     * Gets the name of a day based on a date and current locale.
     * <p>
     * 
     * @param dt
     *            The date.
     * @param fullname
     *            Fetch complete day's name or the short one.
     *            <p>
     * @return A string with the name of the day.
     */
    public static String getDayNameForDate(java.util.Date dt, boolean fullname) {
        // For formatting, if the number of pattern letters is 4 or more,
        // the full form is used; otherwise a short or abbreviated form is used
        // if available. (extracted from Sun's Javadoc)
        final String fullFormat = "EEEE";
        final String smallFormat = "EEE";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(fullname ? fullFormat : smallFormat);
        String dayName = simpleDateFormat.format(dt);
        return (dayName);
    }
}

Related

  1. getDayForDate(String dateToCheck, String pattern)
  2. getDayFormat(Date date)
  3. getDayInWeekBeginAndEnd(Date date)
  4. getDayInWeekForMonthIn2Characters(int year, int month)
  5. getDayName(String dateString)
  6. getDayNames(Locale locale)
  7. getDayNumber()
  8. getDayOfDate(Date date)
  9. getDayOffset(String date, int offset, String format)