List of usage examples for java.util Date getTime
public long getTime()
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 ww w .j a v a 2s . c o 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 long daysBetween(Date d1, Date d2) { return ((d2.getTime() - d1.getTime() + ONE_HOUR) / (ONE_HOUR * 24)); }
From source file:Main.java
public static java.sql.Timestamp convertToSqlTimestamp(Date date) { return new Timestamp(date.getTime()); }
From source file:Main.java
public static Date roundTo30Minutes(final Date from) { long t = from.getTime(); t = t - (t % (1000 * 60 * 30));/*www . j a va2 s. c o m*/ t += (1000 * 60 * 30); return Date.from(Instant.ofEpochMilli(t)); }
From source file:Main.java
public static java.sql.Date convertToSqlDate(Date date) { return new java.sql.Date(date.getTime()); }
From source file:Main.java
public static LocalDate toLocalDate(Date date) { Date lDate = new Date(date.getTime()); return lDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); }
From source file:Main.java
public static LocalDate fromDate(Date date) { Instant instant = Instant.ofEpochMilli(date.getTime()); return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalDate(); }
From source file:Main.java
public static Long GetLong(Date date) { return date.getTime() / 1000L; }
From source file:Main.java
public static long getDateToLong(Date date) { return (date.getTime()); }
From source file:Main.java
public static long getDays(Date start, Date end) { return (end.getTime() - start.getTime()) / (24 * 60 * 60 * 1000); }