List of usage examples for java.util Calendar SEPTEMBER
int SEPTEMBER
To view the source code for java.util Calendar SEPTEMBER.
Click Source Link
From source file:edu.virginia.iath.snac.helpers.datastructures.SNACDate.java
/** * Gets the season dates for the given season and year. Since the season dates only change * +/- 2 days across most of time, we store a lookup table and calculate them directly. * Winter starts in December of the previous year and ends in the given year. * //w w w .j a va 2s . c o m * @param seasonStr Season to lookup (summer, spring, fall, autumn, winter) * @param year 4-digit year. * @return Array of Java Calendar objects containing the beginning and end dates of the season. */ private Calendar[] getSeasonDates(String seasonStr, int year) { Calendar[] seasonDates = new Calendar[2]; String season = seasonStr.toLowerCase().trim(); seasonDates[0] = Calendar.getInstance(); seasonDates[1] = Calendar.getInstance(); // Note: Java is WEIRD: 0 = JANUARY, 1 = FEBRUARY, ... if (season.equals("winter")) { seasonDates[0].set(year - 1, Calendar.DECEMBER, 21); seasonDates[1].set(year, Calendar.MARCH, 19); } else if (season.equals("spring")) { seasonDates[0].set(year, Calendar.MARCH, 20); seasonDates[1].set(year, Calendar.JUNE, 20); } else if (season.equals("fall") || season.equals("autumn")) { seasonDates[0].set(year, Calendar.SEPTEMBER, 22); seasonDates[1].set(year, Calendar.DECEMBER, 20); } else if (season.equals("summer")) { seasonDates[0].set(year, Calendar.JUNE, 21); seasonDates[1].set(year, Calendar.SEPTEMBER, 21); } return seasonDates; }
From source file:org.richfaces.component.CalendarComponentTest.java
public void testCalendarTime() throws Exception { Calendar calendarObject = Calendar.getInstance(); calendarObject.clear();//from w ww . j av a2s . c o m calendarObject.set(2001, Calendar.SEPTEMBER, 11, 13, 36); assertEquals(calendarObject.getTime().toString(), calendar2.getValue().toString()); }
From source file:Time.java
/** * Testing this class./* w w w. j a v a2s.co m*/ * * @param args * Not used. */ public static void main(String[] args) { // This proves that there are 912 days between the two major // terrorist attacks, not 911 as is common knowledge. Day september11 = new Day(2001, Calendar.SEPTEMBER, 11); Day march11 = new Day(2004, Calendar.MARCH, 11); System.out.println(september11.daysBetween(march11)); // This proves that Kennedy was president for 1037 days, // not 1000 as is the popular belief nor 1036 which is the // bluffers reply. Nerds knows when to add one... Day precidency = new Day(1961, Calendar.JANUARY, 20); Day assasination = new Day(1963, Calendar.NOVEMBER, 22); System.out.println(precidency.daysBetween(assasination) + 1); // Niel Armstrong walked the moon on a Sunday Day nielOnMoon = new Day(1969, Calendar.JULY, 20); System.out.println(nielOnMoon.getDayNumberOfWeek()); // Find last tuesdays for 2005 for (int i = 0; i < 12; i++) { Day tuesday = Day.getLastOfMonth(Calendar.TUESDAY, i, 2005); System.out.println(tuesday); } }
From source file:Time.java
/** * Return the 1-based month number of the month of this day. 1 = January, 2 = * February and so on.//from w ww . j ava 2 s. c om * * @return Month number of this month */ public int getMonthNo() { // It is tempting to return getMonth() + 1 but this is conceptually // wrong, as Calendar month is an enumeration and the values are tags // only and can be anything. switch (getMonth()) { case Calendar.JANUARY: return 1; case Calendar.FEBRUARY: return 2; case Calendar.MARCH: return 3; case Calendar.APRIL: return 4; case Calendar.MAY: return 5; case Calendar.JUNE: return 6; case Calendar.JULY: return 7; case Calendar.AUGUST: return 8; case Calendar.SEPTEMBER: return 9; case Calendar.OCTOBER: return 10; case Calendar.NOVEMBER: return 11; case Calendar.DECEMBER: return 12; } // This will never happen return 0; }
From source file:org.apache.james.protocols.imap.utils.DecoderUtilsTest.java
@Test public void testDecodeMonth() throws Exception { assertEquals(Calendar.JANUARY, DecoderUtils.decodeMonth('J', 'A', 'N')); assertEquals(Calendar.JANUARY, DecoderUtils.decodeMonth('j', 'a', 'n')); assertEquals(Calendar.FEBRUARY, DecoderUtils.decodeMonth('F', 'E', 'B')); assertEquals(Calendar.FEBRUARY, DecoderUtils.decodeMonth('f', 'e', 'b')); assertEquals(Calendar.MARCH, DecoderUtils.decodeMonth('M', 'A', 'R')); assertEquals(Calendar.MARCH, DecoderUtils.decodeMonth('m', 'a', 'r')); assertEquals(Calendar.APRIL, DecoderUtils.decodeMonth('A', 'P', 'R')); assertEquals(Calendar.APRIL, DecoderUtils.decodeMonth('a', 'p', 'r')); assertEquals(Calendar.MAY, DecoderUtils.decodeMonth('M', 'A', 'Y')); assertEquals(Calendar.MAY, DecoderUtils.decodeMonth('m', 'a', 'y')); assertEquals(Calendar.JUNE, DecoderUtils.decodeMonth('J', 'U', 'N')); assertEquals(Calendar.JUNE, DecoderUtils.decodeMonth('j', 'u', 'n')); assertEquals(Calendar.JULY, DecoderUtils.decodeMonth('J', 'U', 'L')); assertEquals(Calendar.JULY, DecoderUtils.decodeMonth('j', 'u', 'l')); assertEquals(Calendar.AUGUST, DecoderUtils.decodeMonth('A', 'U', 'G')); assertEquals(Calendar.AUGUST, DecoderUtils.decodeMonth('a', 'u', 'g')); assertEquals(Calendar.SEPTEMBER, DecoderUtils.decodeMonth('S', 'E', 'P')); assertEquals(Calendar.SEPTEMBER, DecoderUtils.decodeMonth('s', 'e', 'p')); assertEquals(Calendar.OCTOBER, DecoderUtils.decodeMonth('O', 'C', 'T')); assertEquals(Calendar.OCTOBER, DecoderUtils.decodeMonth('o', 'c', 't')); assertEquals(Calendar.NOVEMBER, DecoderUtils.decodeMonth('N', 'O', 'V')); assertEquals(Calendar.NOVEMBER, DecoderUtils.decodeMonth('n', 'o', 'v')); assertEquals(Calendar.DECEMBER, DecoderUtils.decodeMonth('D', 'E', 'C')); assertEquals(Calendar.DECEMBER, DecoderUtils.decodeMonth('d', 'e', 'c')); }
From source file:org.hawkular.alerts.api.model.action.TimeConstraint.java
private int month(String sMonth) { if (isEmpty(sMonth)) { return -1; }/* w w w . j a va2 s.c o m*/ if (sMonth.length() < 3) { return -1; } String prefix = sMonth.substring(0, 3).toLowerCase(); MONTH m = MONTH.fromString(prefix); if (m == null) { return -1; } switch (m) { case JANUARY: return Calendar.JANUARY; case FEBRUARY: return Calendar.FEBRUARY; case MARCH: return Calendar.MARCH; case APRIL: return Calendar.APRIL; case MAY: return Calendar.MAY; case JUNE: return Calendar.JUNE; case JULY: return Calendar.JULY; case AUGUST: return Calendar.AUGUST; case SEPTEMBER: return Calendar.SEPTEMBER; case OCTOBER: return Calendar.OCTOBER; case NOVEMBER: return Calendar.NOVEMBER; case DECEMBER: return Calendar.DECEMBER; default: return -1; } }
From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java
public static int getDaysInMonth(int month, int year) { switch (month) { case Calendar.JANUARY: case Calendar.MARCH: case Calendar.MAY: case Calendar.JULY: case Calendar.AUGUST: case Calendar.OCTOBER: case Calendar.DECEMBER: return 31; case Calendar.APRIL: case Calendar.JUNE: case Calendar.SEPTEMBER: case Calendar.NOVEMBER: return 30; case Calendar.FEBRUARY: // This is not correct. See isLeapYear(int) above //return (year % 4 == 0) ? 29 : 28; return isLeapYear(year) ? 29 : 28; default:/*w ww. ja v a 2 s . co m*/ throw new IllegalArgumentException("Invalid Month"); } }
From source file:com.tr4android.support.extension.picker.date.SimpleMonthView.java
private static int getDaysInMonth(int month, int year) { switch (month) { case Calendar.JANUARY: case Calendar.MARCH: case Calendar.MAY: case Calendar.JULY: case Calendar.AUGUST: case Calendar.OCTOBER: case Calendar.DECEMBER: return 31; case Calendar.APRIL: case Calendar.JUNE: case Calendar.SEPTEMBER: case Calendar.NOVEMBER: return 30; case Calendar.FEBRUARY: return (year % 4 == 0) ? 29 : 28; default:/* ww w. j a v a 2s . c o m*/ throw new IllegalArgumentException("Invalid Month"); } }
From source file:com.marklogic.client.test.PojoFacadeTest.java
@Test public void testF_DateTime() { PojoRepository<TimeTest, String> times = Common.client.newPojoRepository(TimeTest.class, String.class); GregorianCalendar septFirst = new GregorianCalendar(TimeZone.getTimeZone("CET")); septFirst.set(2014, Calendar.SEPTEMBER, 1, 12, 0, 0); TimeTest timeTest1 = new TimeTest("1", septFirst); times.write(timeTest1);// ww w . ja v a 2 s . c o m TimeTest timeTest1FromDb = times.read("1"); assertEquals("Times should be equal", timeTest1.timeTest.getTime().getTime(), timeTest1FromDb.timeTest.getTime().getTime()); GregorianCalendar septFirstGMT = new GregorianCalendar(TimeZone.getTimeZone("GMT")); septFirstGMT.set(2014, Calendar.SEPTEMBER, 1, 12, 0, 0); TimeTest timeTest2 = new TimeTest("2", septFirstGMT); times.write(timeTest2); TimeTest timeTest2FromDb = times.read("2"); assertEquals("Times should be equal", timeTest2.timeTest, timeTest2FromDb.timeTest); }
From source file:cn.mljia.common.notify.utils.DateUtils.java
/** * ?/*from ww w .j a v a2 s.c om*/ * * @param date * @return */ public static Date[] getSeasonDate(Date date) { Date[] season = new Date[3]; Calendar c = Calendar.getInstance(); c.setTime(date); int nSeason = getSeason(date); if (nSeason == 1) {// c.set(Calendar.MONTH, Calendar.JANUARY); season[0] = c.getTime(); c.set(Calendar.MONTH, Calendar.FEBRUARY); season[1] = c.getTime(); c.set(Calendar.MONTH, Calendar.MARCH); season[2] = c.getTime(); } else if (nSeason == 2) {// c.set(Calendar.MONTH, Calendar.APRIL); season[0] = c.getTime(); c.set(Calendar.MONTH, Calendar.MAY); season[1] = c.getTime(); c.set(Calendar.MONTH, Calendar.JUNE); season[2] = c.getTime(); } else if (nSeason == 3) {// c.set(Calendar.MONTH, Calendar.JULY); season[0] = c.getTime(); c.set(Calendar.MONTH, Calendar.AUGUST); season[1] = c.getTime(); c.set(Calendar.MONTH, Calendar.SEPTEMBER); season[2] = c.getTime(); } else if (nSeason == 4) {// c.set(Calendar.MONTH, Calendar.OCTOBER); season[0] = c.getTime(); c.set(Calendar.MONTH, Calendar.NOVEMBER); season[1] = c.getTime(); c.set(Calendar.MONTH, Calendar.DECEMBER); season[2] = c.getTime(); } return season; }