List of usage examples for java.util GregorianCalendar setTimeZone
@Override public void setTimeZone(TimeZone zone)
From source file:com.projity.contrib.calendar.ContribIntervals.java
public static GregorianCalendar calendarInstance() { GregorianCalendar cal = new GregorianCalendar(); cal.setTimeZone(DateUtils.UTC_TIME_ZONE); return cal;//from w ww . j a va 2s . com }
From source file:org.springframework.cloud.netflix.rx.ObservableSseEmitterTest.java
private static Date getDate(int year, int month, int day) { GregorianCalendar calendar = new GregorianCalendar(year, month, day, 12, 0, 0); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); return calendar.getTime(); }
From source file:DateUtility.java
/** * This will retun the first millisecond of the month * that contains the timestamp provided//from ww w .ja v a2s.co m * @param timestamp * @return long */ static public long getFirstMilliOfMonth(long timestamp, TimeZone tz) { GregorianCalendar cal = new GregorianCalendar(); cal.setTimeZone(tz); cal.setTime(new Date(timestamp)); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); return date.getTime(); }
From source file:DateUtility.java
/** * Gets the last millsecond of the month, according to the timestamp and * timezone arguments.//from ww w . j a v a2 s. c o m * @param timestamp * @param tz * @return long */ static public long getLastMilliOfMonth(long timestamp, TimeZone tz) { timestamp = getFirstMilliOfMonth(timestamp, tz); GregorianCalendar cal = new GregorianCalendar(); cal.setTimeZone(tz); cal.setTime(new Date(timestamp)); // now we'll roll the calendar forward one month. // in the case of december, we need to roll forward the year too if (cal.get(GregorianCalendar.MONTH) == GregorianCalendar.DECEMBER) { cal.roll(GregorianCalendar.YEAR, true); } cal.roll(GregorianCalendar.MONTH, true); long date = cal.getTime().getTime(); date = date - 1L; return date; }
From source file:DateUtility.java
/** * This utility returns the first millsecond * of the month, and year, and timezone supplied as arguments. * * @param int month/*from w w w. ja v a 2s . c om*/ * @param int year * @param TimeZone tz * @return long */ static public long getFirstMilliOfMonth(int year, int month, TimeZone tz) { GregorianCalendar cal = new GregorianCalendar(year, (month - 1), 1); cal.setTimeZone(tz); return cal.getTime().getTime(); }
From source file:Main.java
public static XMLGregorianCalendar getXMLDate(final Calendar calendar) { GregorianCalendar c; if (calendar instanceof GregorianCalendar) { c = (GregorianCalendar) calendar; } else {/*from w w w . j av a 2s . c o m*/ c = new GregorianCalendar(); c.setTimeZone(UTC); c.setTime(calendar.getTime()); } try { XMLGregorianCalendar ret = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); ret.setMillisecond(DatatypeConstants.FIELD_UNDEFINED); return ret; } catch (DatatypeConfigurationException e) { return null; } }
From source file:DateUtility.java
/** * This utility returns the last millsecond * of the month, and year, and timezone supplied as arguments. * * @param int month//from w w w . j av a2 s .c o m * @param int year * @param TimeZone tz * @return long */ static public long getLastMilliOfMonth(int year, int month, TimeZone tz) { GregorianCalendar cal = new GregorianCalendar(year, (month - 1), 1); cal.setTimeZone(tz); // set the maximum last day int lastday = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH); cal.set(GregorianCalendar.DAY_OF_MONTH, lastday); // set other calendar maximums. - we should do this programatically // too but i'm too lazy, and i dont think they're gonna change the gregorian // calendar anytime soon.. eh? cal.set(GregorianCalendar.HOUR_OF_DAY, 23); cal.set(GregorianCalendar.MINUTE, 59); cal.set(GregorianCalendar.SECOND, 59); cal.set(GregorianCalendar.MILLISECOND, 999); long time = cal.getTime().getTime(); return time; }
From source file:DateUtils.java
public static final GregorianCalendar getCurrentCalendar(String utimezonestring) { try {//from w ww . j av a 2 s . c o m GregorianCalendar gc = new GregorianCalendar(); gc.setTimeZone(TimeZone.getTimeZone(utimezonestring)); return gc; } catch (Exception e) { //If exception, return server TimeStamp return new GregorianCalendar(); } }
From source file:DateUtils.java
public static final String dateToString(Date dt, String tzString, String dateformat) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(dt);//from w w w. ja va 2 s .c o m cal.setTimeZone(TimeZone.getTimeZone(tzString)); StringBuffer ret = new StringBuffer(); String separator = new String(); if (dateformat.equals(DateUtils.FORMAT_YYYYMMDD)) { separator = "-"; } if (dateformat.equals(DateUtils.FORMAT_YYYYMMDD_SLASHES)) { separator = "/"; } ret.append(cal.get(Calendar.YEAR)); ret.append(separator); ret.append(cal.get(Calendar.MONTH) + 1); ret.append(separator); ret.append(cal.get(Calendar.DATE)); return ret.toString(); }
From source file:DateUtils.java
public static final String getTimeFromDate(Date dt, String tzString) { try {/*from www . j a va2 s . co m*/ GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dt); gc.setTimeZone(TimeZone.getTimeZone(tzString)); StringBuffer ret = new StringBuffer(); ret.append(gc.get(Calendar.HOUR)); ret.append(":"); ret.append(gc.get(Calendar.MINUTE)); ret.append(" "); if (gc.get(Calendar.AM_PM) == 0) { ret.append("AM"); } else { ret.append("PM"); } return ret.toString(); } catch (Exception e) { return ""; } }