Here you can find the source of Day_Of_Week(String Date, int DayCase)
Parameter | Description |
---|---|
Date | a parameter |
DayCase | a parameter |
public static String Day_Of_Week(String Date, int DayCase)
//package com.java2s; /*/*from w ww. j av a 2s . c o m*/ * Created on Oct 23, 2003 * * Copyright (c) 2005 Derone Bryson * * 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, or (at your option) any later version. * * 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. * * You should have received a copy of the GNU General Public License along with * this software; see the file COPYING. If not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * As a special exception, Derone Bryson and the StopMojo Project gives * permission for additional uses of the text contained in its release of * StopMojo. * * The exception is that, Derone Bryson and the the StopMojo Project hereby * grants permission for non-GPL compatible modules (jar files, libraries, * codecs, etc.) to be used and distributed together with StopMojo. This * permission is above and beyond the permissions granted by the GPL license * StopMojo is covered by. * * This exception does not however invalidate any other reasons why the * executable file might be covered by the GNU General Public License. * * This exception applies only to the code released by Derone Bryson and/or the * StopMojo Project under the name StopMojo. If you copy code from other Free * Software Foundation releases into a copy of StopMojo, as the General Public * License permits, the exception does not apply to the code that you add in * this way. To avoid misleading anyone as to the status of such modified files, * you must delete this exception notice from them. * * If you write modifications of your own for StopMojo, it is your choice * whether to permit this exception to apply to your modifications. If you do * not wish that, delete this exception notice. */ public class Main { private static String[] DOW = { "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" }; /** * * @param Date * @param DayCase * @return */ public static String Day_Of_Week(String Date, int DayCase) /* * Returns the day of the week in *Buffer for the calendar date passed in * *Date in the form MM/DD/YY. The following formats are selected by * DayCase: DayCase = 1 - MON, TUE, WED, THU... DayCase = 2 - Mon, Tue, Wed, * Thu... DayCase = 3 - mon, tue, wed, thu... DayCase = 4 - MONDAY, TUESDAY, * WEDNESDAY.... DayCase = 5 - Monday, Tuesday, Wednesday.... DayCase = 6 - * monday, tuesday, wednesday.... */ {/* Day_Of_Week */ StringBuffer dow = new StringBuffer( DOW[(int) (Math.floor((Cal_Julian(Date) + 2) - (Math.floor((Cal_Julian(Date) + 2) / 7) * 7)))]); /* If DayCase 1, 2, or 3 copy only first 3 characters of day name */ if ((DayCase == 1) || (DayCase == 2) || (DayCase == 3)) dow = new StringBuffer(dow.substring(0, 3)); switch (DayCase) { case 1: case 4: /* Uppercase full name */ return dow.toString().toUpperCase(); case 2: case 5: /* Uppercase first letter only */ dow.setCharAt(0, Character.toUpperCase(dow.charAt(0))); return dow.toString(); } /* switch */ return ""; } /** * * @param DateVar * @return */ public static double Cal_Julian(String DateVar) { double MonthV, /* Month value */ YearV, /* Year value */ DayV, /* Day value */ Yl; /* Temporary work variables */ /* Parse out the month, day, and year */ YearV = atof(DateVar.substring(6)); DayV = atof(DateVar.substring(3)); MonthV = atof(DateVar); /* Adjust for the 20th century */ if (YearV < 50.0) /* = 40.0) */ YearV += 2000; else YearV += 1900; Yl = YearV + (MonthV - 2.85) / 12; return (Math.floor( Math.floor(Math.floor(367.0 * Yl) - Math.floor(Yl) - 0.75 * Math.floor(Yl) + DayV) - 0.75 * 2.0) + 1721115.0); } /** * Returns the double value of s. * * @param s * the string containing the floating point number * @return the value of the floating point number in s */ public static double atof(String s) { int i, numMinuses = 0, numDots = 0; s = s.trim(); for (i = 0; i < s.length() && (s.charAt(i) == '-' || s.charAt(i) == '.' || Character.isDigit(s.charAt(i))); i++) if (s.charAt(i) == '-') numMinuses++; else if (s.charAt(i) == '.') numDots++; if (i != 0 && numMinuses < 2 && numDots < 2) return Double.parseDouble(s.substring(0, i)); return 0.0; } }