List of usage examples for java.util Calendar JANUARY
int JANUARY
To view the source code for java.util Calendar JANUARY.
Click Source Link
From source file:Main.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: return (year % 4 == 0) ? 29 : 28; default:// www . j a va 2s .c om throw new IllegalArgumentException("Invalid Month"); } }
From source file:Main.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: return (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? 29 : 28; default:/*www . j a va2s . c om*/ throw new IllegalArgumentException("Invalid Month"); } }
From source file:Main.java
/** Helper method - creates a Phoenix date <I>String</I> from a Date object. @param dteValue <I>Date</I> object to be converted. @return A <I>String</I> that follows the format "YYYY-MM-DDTHH:NN:SS.00000". *//*from w ww. ja v a2s. co m*/ public static String getXMLStringFromDate(Date dteValue) { if (null == dteValue) return null; Calendar pCalendar = Calendar.getInstance(); pCalendar.setTime(dteValue); // Return the String value. // Special treatment for the month because the current implementation // values January as 0. Code below should work if that ever changes. return pCalendar.get(Calendar.YEAR) + "-" + padNumber(pCalendar.get(Calendar.MONTH) + 1 - Calendar.JANUARY) + "-" + padNumber(pCalendar.get(Calendar.DAY_OF_MONTH)) + "T" + padNumber(pCalendar.get(Calendar.HOUR_OF_DAY)) + ":" + padNumber(pCalendar.get(Calendar.MINUTE)) + ":" + padNumber(pCalendar.get(Calendar.SECOND)); }
From source file:Main.java
public static int stringMonthToInt(@NonNull final String month) { switch (month) { case "Jan": return Calendar.JANUARY; case "Feb": return Calendar.FEBRUARY; case "Mar": return Calendar.MARCH; case "Apr": return Calendar.APRIL; case "May": return Calendar.MAY; case "Jun": return Calendar.JUNE; case "Jul": return Calendar.JULY; case "Aug": return Calendar.AUGUST; case "Sep": return Calendar.SEPTEMBER; case "Oct": return Calendar.OCTOBER; case "Nov": return Calendar.NOVEMBER; case "Dec": return Calendar.DECEMBER; default:/* ww w. j ava 2 s. c om*/ return 0; } }
From source file:Main.java
public static int getMonth(String str) { if (str.equals("jan")) return Calendar.JANUARY; if (str.equals("feb")) return Calendar.FEBRUARY; if (str.equals("mar")) return Calendar.MARCH; if (str.equals("apr")) return Calendar.APRIL; if (str.equals("may")) return Calendar.MAY; if (str.equals("jun")) return Calendar.JUNE; if (str.equals("jul")) return Calendar.JULY; if (str.equals("aug")) return Calendar.AUGUST; if (str.equals("sep")) return Calendar.SEPTEMBER; if (str.equals("oct")) return Calendar.OCTOBER; if (str.equals("nov")) return Calendar.NOVEMBER; if (str.equals("dec")) return Calendar.DECEMBER; return -1;/*from ww w . j a v a 2s.c o m*/ }
From source file:Util.java
private static int getMonthLastDate(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; default: // Calendar.FEBRUARY return year % 4 == 0 ? 29 : 28; }/*from www . ja va 2s. c om*/ }
From source file:Main.java
public static String getDateString() { String stringDate = ""; Calendar calendar = Calendar.getInstance(); int day = calendar.get(Calendar.DAY_OF_WEEK); int month = calendar.get(Calendar.MONTH); int dayInt = calendar.get(Calendar.DAY_OF_MONTH); switch (day) { case Calendar.SUNDAY: stringDate += "Sunday"; break;/*from w ww. j av a 2s .c o m*/ case Calendar.MONDAY: stringDate += "Monday"; break; case Calendar.TUESDAY: stringDate += "Tuesday"; break; case Calendar.WEDNESDAY: stringDate += "Wednesday"; break; case Calendar.THURSDAY: stringDate += "Thursday"; break; case Calendar.FRIDAY: stringDate += "Friday"; break; case Calendar.SATURDAY: stringDate += "Saturday"; break; } switch (month) { case Calendar.JANUARY: stringDate += ", January"; break; case Calendar.FEBRUARY: stringDate += ", February"; break; case Calendar.MARCH: stringDate += ", March"; break; case Calendar.APRIL: stringDate += ", April"; break; case Calendar.MAY: stringDate += ", May"; break; case Calendar.JUNE: stringDate += ", June"; break; case Calendar.JULY: stringDate += ", July"; break; case Calendar.AUGUST: stringDate += ", August"; break; case Calendar.SEPTEMBER: stringDate += ", September"; break; case Calendar.OCTOBER: stringDate += ", October"; break; case Calendar.NOVEMBER: stringDate += ", November"; break; case Calendar.DECEMBER: stringDate += ", December"; break; } stringDate += (" " + dayInt); return stringDate; }
From source file:Util.java
public static Date getMonday(Date today) { Calendar cal = Calendar.getInstance(); cal.setTime(today);/*from w ww . java2s .co m*/ int dow = cal.get(Calendar.DAY_OF_WEEK); while (dow != Calendar.MONDAY) { int date = cal.get(Calendar.DATE); if (date == 1) { int month = cal.get(Calendar.MONTH); if (month == Calendar.JANUARY) { month = Calendar.DECEMBER; cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) - 1); } else { month--; } cal.set(Calendar.MONTH, month); date = getMonthLastDate(month, cal.get(Calendar.YEAR)); } else { date--; } cal.set(Calendar.DATE, date); dow = cal.get(Calendar.DAY_OF_WEEK); } return cal.getTime(); }
From source file:Main.java
@NonNull static Date convertDate(int date, int time) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 1997); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR_OF_DAY, time / 60); calendar.set(Calendar.MINUTE, time % 60); calendar.add(Calendar.DATE, date); return calendar.getTime(); }
From source file:Main.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: return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) ? 29 : 28; default:/* w w w .j av a 2 s . c o m*/ throw new IllegalArgumentException("Invalid Month"); } }