List of usage examples for java.util GregorianCalendar set
public final void set(int year, int month, int date, int hourOfDay, int minute, int second)
YEAR
, MONTH
, DAY_OF_MONTH
, HOUR_OF_DAY
, MINUTE
, and SECOND
. From source file:Main.java
public static void main(String[] argv) throws Exception { GregorianCalendar newCal = new GregorianCalendar(); int day = newCal.get(Calendar.DAY_OF_WEEK); newCal = new GregorianCalendar(); newCal.set(1997, 2, 1, 0, 0, 0); newCal.setTime(newCal.getTime());//from w w w . j a v a 2 s . com day = newCal.get(Calendar.DAY_OF_WEEK); }
From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java
public static void main(String[] args) { ICalTimeZone tzUTC = ICalTimeZone.getUTC(); TimeZoneMap tzmap = new TimeZoneMap(tzUTC); ParsedDateTime dtStart = null;//from w w w. j a va 2 s .co m try { dtStart = ParsedDateTime.parse("20050101T123456", tzmap, tzUTC, tzUTC); } catch (ParseException e) { System.out.println("Caught ParseException at start: " + e); } Date rangeStart; Date rangeEnd; GregorianCalendar cal = new GregorianCalendar(); cal.clear(); cal.setTimeZone(tzUTC); cal.set(2005, 4, 15, 0, 0, 0); rangeStart = cal.getTime(); cal.set(2006, 0, 1, 0, 0, 0); rangeEnd = cal.getTime(); try { ZRecur test = new ZRecur("FREQ=DAILY;BYMONTH=5,6", tzmap); System.out.println("\n\n" + test.toString() + "\n-------------------------------------------------"); List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime()); for (Date d : dateList) { cal.setTime(d); cal.setTimeZone(tzUTC); System.out.printf("%tc\n", cal); } } catch (ServiceException e) { System.out.println("Caught ServiceException" + e); e.printStackTrace(); } try { ZRecur test = new ZRecur("FREQ=DAILY;BYMONTH=5,6;BYDAY=TH,-1MO", tzmap); System.out.println("\n\n" + test.toString() + "\n-------------------------------------------------"); List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime()); for (Date d : dateList) { cal.setTime(d); cal.setTimeZone(tzUTC); System.out.printf("%tc\n", cal); } } catch (ServiceException e) { System.out.println("Caught ServiceException" + e); e.printStackTrace(); } try { ZRecur test = new ZRecur("FREQ=DAILY;BYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31", tzmap); System.out.println("\n\n" + test.toString() + "\n-------------------------------------------------"); List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime()); for (Date d : dateList) { cal.setTime(d); System.out.printf("%tc\n", cal); } } catch (ServiceException e) { System.out.println("Caught ServiceException" + e); e.printStackTrace(); } try { ZRecur test = new ZRecur("FREQ=DAILY;BYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31;BYDAY=SU,SA", tzmap); System.out.println( "\n\n" + test.toString() + "\n--------------------------------------------------------------"); List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime()); for (Date d : dateList) { cal.setTime(d); System.out.printf("%tc\n", cal); } } catch (ServiceException e) { System.out.println("Caught ServiceException" + e); e.printStackTrace(); } try { ZRecur test = new ZRecur("FREQ=DAILY;BYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31;BYDAY=SU,SA;BYHOUR=21,0", tzmap); System.out.println( "\n\n" + test.toString() + "\n--------------------------------------------------------------"); List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime()); for (Date d : dateList) { cal.setTime(d); System.out.printf("%tc\n", cal); } } catch (ServiceException e) { System.out.println("Caught ServiceException" + e); e.printStackTrace(); } try { ZRecur test = new ZRecur( "FREQ=DAILY;BYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31;BYDAY=SU;BYHOUR=21,0;BYMINUTE=23", tzmap); System.out.println( "\n\n" + test.toString() + "\n--------------------------------------------------------------"); List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime()); for (Date d : dateList) { cal.setTime(d); System.out.printf("%tc\n", cal); } } catch (ServiceException e) { System.out.println("Caught ServiceException" + e); e.printStackTrace(); } try { ZRecur test = new ZRecur( "FREQ=DAILY;BYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31;BYDAY=SU;BYHOUR=1,21,0;BYSECOND=0,59", tzmap); System.out.println( "\n\n" + test.toString() + "\n--------------------------------------------------------------"); List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime()); for (Date d : dateList) { cal.setTime(d); System.out.printf("%tc\n", cal); } } catch (ServiceException e) { System.out.println("Caught ServiceException" + e); e.printStackTrace(); } try { // parse error testing ZRecur test = new ZRecur( "FREQ=DAILY;BIYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31;BYDAY=SU;BYHOUR=1,21,0;BYSECOND=0,59;BYSETPOS=1,-1,3,1000,,-1000", tzmap); System.out.println( "\n\n" + test.toString() + "\n--------------------------------------------------------------"); List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime()); for (Date d : dateList) { cal.setTime(d); System.out.printf("%tc\n", cal); } } catch (ServiceException e) { System.out.println("Caught ServiceException" + e); e.printStackTrace(); } try { ZRecur test = new ZRecur("FREQ=HOURLY;BIYMONTH=6;BYMONTHDAY=1,3;BYHOUR=2,14", tzmap); System.out.println( "\n\n" + test.toString() + "\n--------------------------------------------------------------"); List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime()); for (Date d : dateList) { cal.setTime(d); System.out.printf("%tc\n", cal); } } catch (ServiceException e) { System.out.println("Caught ServiceException" + e); e.printStackTrace(); } try { ZRecur test = new ZRecur("FREQ=HOURLY;BIYMONTH=6;BYMONTHDAY=1;;BYMINUTE=10;BYSECOND=11,12", tzmap); System.out.println( "\n\n" + test.toString() + "\n--------------------------------------------------------------"); List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime()); for (Date d : dateList) { cal.setTime(d); System.out.printf("%tc\n", cal); } } catch (ServiceException e) { System.out.println("Caught ServiceException" + e); e.printStackTrace(); } cal.set(2010, 0, 1, 0, 0, 0); rangeEnd = cal.getTime(); try { ZRecur test = new ZRecur("FREQ=YEARLY", tzmap); System.out.println( "\n\n" + test.toString() + "\n--------------------------------------------------------------"); List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime()); for (Date d : dateList) { cal.setTime(d); System.out.printf("%tc\n", cal); } } catch (ServiceException e) { System.out.println("Caught ServiceException" + e); e.printStackTrace(); } try { ZRecur test = new ZRecur("FREQ=YEARLY;BYYEARDAY=-1", tzmap); System.out.println( "\n\n" + test.toString() + "\n--------------------------------------------------------------"); List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime()); for (Date d : dateList) { cal.setTime(d); System.out.printf("%tc\n", cal); } } catch (ServiceException e) { System.out.println("Caught ServiceException" + e); e.printStackTrace(); } try { ZRecur test = new ZRecur("FREQ=SECONDLY", tzmap); System.out.println( "\n\n" + test.toString() + "\n--------------------------------------------------------------"); List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime()); for (Date d : dateList) { cal.setTime(d); System.out.printf("%tc\n", cal); } } catch (ServiceException e) { System.out.println("Caught ServiceException" + e); e.printStackTrace(); } try { ParsedDateTime myDtStart = ParsedDateTime.parse("16010101T020000", tzmap, tzUTC, tzUTC); ZRecur test = new ZRecur("FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=12;BYDAY=-1SU", tzmap); System.out.println( "\n\n" + test.toString() + "\n--------------------------------------------------------------"); List<Date> dateList = test.expandRecurrenceOverRange(myDtStart, rangeStart.getTime(), rangeEnd.getTime()); for (Date d : dateList) { cal.setTime(d); System.out.printf("%tc\n", cal); } } catch (ParseException e) { System.out.println("Caught ParseException" + e); e.printStackTrace(); } catch (ServiceException e) { System.out.println("Caught ServiceException" + e); e.printStackTrace(); } cal.set(2010, 0, 1, 0, 0, 0); rangeEnd = cal.getTime(); try { ZRecur test = new ZRecur("FREQ=YEARLY;BYMONTH=12;BYDAY=1WE", tzmap); System.out.println( "\n\n" + test.toString() + "\n--------------------------------------------------------------"); List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime()); for (Date d : dateList) { cal.setTime(d); System.out.printf("%tc\n", cal); } } catch (ServiceException e) { System.out.println("Caught ServiceException" + e); e.printStackTrace(); } }
From source file:Main.java
public static GregorianCalendar calendarFromBytes(byte[] buffer, int offset) { if (offset + 5 > buffer.length) return null; GregorianCalendar cal = new GregorianCalendar(); cal.set(buffer[offset] + 2000, buffer[offset + 1], buffer[offset + 2], buffer[offset + 3], buffer[offset + 4], buffer[offset + 5]); return cal;/*from w w w .j av a 2s. c om*/ }
From source file:Main.java
public static long getMonthTimeMilis(long l, int i) { Date date = new Date(l); GregorianCalendar gregoriancalendar = new GregorianCalendar(); gregoriancalendar.set(date.getYear() + 1900, i, 1, 0, 0, 0); gregoriancalendar.set(14, 0);/* ww w.jav a 2 s .c o m*/ return gregoriancalendar.getTimeInMillis(); }
From source file:Main.java
public static long convertTime(long time) { GregorianCalendar t1 = new GregorianCalendar(TimeZone.getTimeZone("America/Los_Angeles")); t1.setTimeInMillis(time);/*from w ww . j a va 2 s .com*/ GregorianCalendar t2 = new GregorianCalendar(); t2.set(t1.get(GregorianCalendar.YEAR), t1.get(GregorianCalendar.MONTH), t1.get(GregorianCalendar.DAY_OF_MONTH), t1.get(GregorianCalendar.HOUR_OF_DAY), t1.get(GregorianCalendar.MINUTE), t1.get(GregorianCalendar.SECOND)); return t2.getTimeInMillis(); }
From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.framework.Util.java
public static Date getUTCDate(int year, int month, int day, int hour, int minute, int second) { GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("utc")); int dateMonth = month - 1; calendar.set(year, dateMonth, day, hour, minute, second); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTime(); }
From source file:org.energyos.espi.common.test.EspiFactory.java
public static GregorianCalendar newCalendar(int year, int month, int date) { GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT+00:00")); calendar.set(year, month, date, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.getTime();// w w w . j a v a 2 s . co m return calendar; }
From source file:ebay.dts.client.BulkDataExchangeActions.java
private static XMLGregorianCalendar parseDate(String cal) throws DatatypeConfigurationException { GregorianCalendar ret = null; SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); try {// ww w.j a v a2 s.c o m df.parse(cal); String[] parts = cal.split("-"); ret = (GregorianCalendar) Calendar.getInstance(); ret.set(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]) - 1, Integer.parseInt(parts[2]), 0, 0, 0); // get here and we know the format is correct } catch (ParseException e) { logger.error("ParseException caught when parsing your date string, please fix it and retry."); return null; } DatatypeFactory factory = DatatypeFactory.newInstance(); XMLGregorianCalendar xmlGregorianCalendar = factory.newXMLGregorianCalendar(ret); return xmlGregorianCalendar; }
From source file:org.getobjects.appserver.core.WOMessage.java
public static Date dateFromHttpFormattedString(final String _httpDate) { int dayOfMonth = Integer.parseInt(_httpDate.substring(5, 7)); int year = Integer.parseInt(_httpDate.substring(12, 16)); int hourOfDay = Integer.parseInt(_httpDate.substring(17, 19)); int minute = Integer.parseInt(_httpDate.substring(20, 22)); int second = Integer.parseInt(_httpDate.substring(23, 25)); int monthOfYear; String monthName = _httpDate.substring(8, 11); for (monthOfYear = 0; monthOfYear < 12; monthOfYear++) { if (httpMonthNames[monthOfYear].equals(monthName)) break; }//from ww w. j ava 2 s .c om String tzName = _httpDate.substring(26); TimeZone tz = tzName.equals("GMT") ? gmt : TimeZone.getTimeZone(tzName); GregorianCalendar cal = new GregorianCalendar(); cal.set(year, monthOfYear, dayOfMonth, hourOfDay, minute, second); cal.setTimeZone(tz); return cal.getTime(); }
From source file:org.nex.util.DateUtil.java
/** * <code>timestamp</code> looks like 2013-11-26 11:09:47.403 * @param timestamp//from ww w . j ava 2 s.c o m * @return */ public static Date fromDefaultTimestamp(String timestamp) { System.out.println("DateUtil.fromDefaultTimestamp- " + timestamp); Date result = null; String[] parts = timestamp.split(" "); String big = parts[0]; String small = parts[1]; GregorianCalendar c = new GregorianCalendar(); String[] bigger = big.split("-"); int yr = Integer.parseInt(bigger[0]); int mo = Integer.parseInt(bigger[1]); int da = Integer.parseInt(bigger[2]); String[] smaller = small.split(":"); int hr = Integer.parseInt(smaller[0]); int min = Integer.parseInt(smaller[1]); String x = smaller[2]; int where = x.indexOf('.'); if (where > -1) x = x.substring(0, where); int sec = Integer.parseInt(x); c.set(yr, mo, da, hr, min, sec); result = new Date(c.getTimeInMillis()); return result; }