List of usage examples for java.util GregorianCalendar set
public void set(int field, int value)
From source file:com.esofthead.mycollab.core.utils.DateTimeUtils.java
public static Date getCurrentDateWithoutMS() { GregorianCalendar calendar = new GregorianCalendar(); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MINUTE, 0); return calendar.getTime(); }
From source file:org.onosproject.drivers.bti.Bti7000SnmpAlarmConsumer.java
/** * This method is similar to SNMP4J approach with some fixes for the 11-bytes version (ie the one with timezone * offset).//from w ww. j a va 2s. c o m * <p> * For original makeCalendar refer @see http://www.snmp4j.org/agent/doc/org/snmp4j/agent/mo/snmp/DateAndTime.html * <p> * Creates a <code>GregorianCalendar</code> from a properly formatted SNMP4J DateAndTime <code>OctetString</code>. * * @param dateAndTimeValue an OctetString conforming to the DateAndTime TC. * @return the corresponding <code>GregorianCalendar</code> instance. */ public static GregorianCalendar btiMakeCalendar(OctetString dateAndTimeValue) { int year = (dateAndTimeValue.get(0) & 0xFF) * 256 + (dateAndTimeValue.get(1) & 0xFF); int month = (dateAndTimeValue.get(2) & 0xFF); int date = (dateAndTimeValue.get(3) & 0xFF); int hour = (dateAndTimeValue.get(4) & 0xFF); int minute = (dateAndTimeValue.get(5) & 0xFF); int second = (dateAndTimeValue.get(6) & 0xFF); int deci = (dateAndTimeValue.get(7) & 0xFF); GregorianCalendar gc = new GregorianCalendar(year, month - 1, date, hour, minute, second); gc.set(Calendar.MILLISECOND, deci * 100); if (dateAndTimeValue.length() == 11) { char directionOfOffset = (char) dateAndTimeValue.get(8); int hoursOffset = directionOfOffset == '+' ? dateAndTimeValue.get(9) : -dateAndTimeValue.get(9); org.joda.time.DateTimeZone offset = org.joda.time.DateTimeZone.forOffsetHoursMinutes(hoursOffset, dateAndTimeValue.get(10)); org.joda.time.DateTime dt = new org.joda.time.DateTime(year, month, date, hour, minute, second, offset); return dt.toGregorianCalendar(); } return gc; }
From source file:org.openvpms.web.workspace.workflow.scheduling.SchedulingHelper.java
/** * Returns the time of the slot closest to that of the specified time. * * @param time the time//from w w w.j a v a 2 s .c o m * @param slotSize the size of the slot, in minutes * @param roundUp if {@code true} round up to the nearest slot, otherwise round down * @return the nearest slot time to {@code time} */ public static Date getSlotTime(Date time, int slotSize, boolean roundUp) { Date result; int mins = getMinutes(time); int nearestSlot = getNearestSlot(mins, slotSize); if (nearestSlot != mins) { if (roundUp) { nearestSlot += slotSize; } GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(time); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.add(Calendar.MINUTE, nearestSlot); result = calendar.getTime(); } else { result = time; } return result; }
From source file:DateUtility.java
/** * This will retun the first millisecond of the month * that contains the timestamp provided//from www. j a va2 s. 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:org.nuxeo.ecm.core.opencmis.tests.Helper.java
/** * Gets a Calendar object with a specific timezone *///from w w w. ja v a 2 s.co m public static GregorianCalendar getCalendar(int year, int month, int day, int hours, int minutes, int seconds, TimeZone tz) { GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance(tz); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month - 1); // 0-based cal.set(Calendar.DAY_OF_MONTH, day); cal.set(Calendar.HOUR_OF_DAY, hours); cal.set(Calendar.MINUTE, minutes); cal.set(Calendar.SECOND, seconds); cal.set(Calendar.MILLISECOND, 0); return cal; }
From source file:de.dekarlab.moneybuilder.model.parser.JsonBookLoader.java
/** * Load book from JSON file./*from w w w. j a va 2 s . co m*/ * * @return */ public static Book loadBook(File file) throws Exception { Book book = new Book(); if (!file.exists()) { book.setName("Book"); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(new Date()); cal.set(Calendar.DAY_OF_MONTH, 1); // create period Period newPeriod = new Period(cal.getTime()); newPeriod.setId(Formatter.formatDateId(cal.getTime())); book.getPeriodList().add(newPeriod); book.setCurrPeriod(newPeriod); book.getAssetList().setName(App.getGuiProp("default.assets")); book.getLiabilityList().setName(App.getGuiProp("default.liability")); book.getExpenseList().setName(App.getGuiProp("default.expenses")); book.getIncomeList().setName(App.getGuiProp("default.income")); return book; } FileReader fr = null; try { fr = new FileReader(file); JSONTokener jsonTokener = new JSONTokener(fr); JSONObject root = new JSONObject(jsonTokener); JSONObject jsonBook = root.getJSONObject("book"); book.setName(jsonBook.getString("name")); book.setCurrPeriodId(jsonBook.getString("currPeriodId")); parseAccounts(jsonBook.getJSONObject("assets"), book.getAssetList()); parseAccounts(jsonBook.getJSONObject("liability"), book.getLiabilityList()); parseAccounts(jsonBook.getJSONObject("income"), book.getIncomeList()); parseAccounts(jsonBook.getJSONObject("expenses"), book.getExpenseList()); parsePeriods(jsonBook.getJSONArray("periodList"), book.getPeriodList(), book); } finally { if (fr != null) { fr.close(); } } return book; }
From source file:com.controlj.addon.weather.wbug.service.WeatherBugDataUtils.java
/** * Extracts a timestamp from a XML element. * //from w w w . j a v a 2 s. c o m * @param elem * the element from which the timestamp must be extracted. * @param path * the XPath to be used to locate the value. * @return the extracted timestamp. */ public static Timestamp getTimestamp(Element elem, String path) { Element timestampElem = (Element) elem.selectSingleNode(path); final String tz = WeatherBugDataUtils.getString(timestampElem, "aws:time-zone/@abbrv") != null ? WeatherBugDataUtils.getString(timestampElem, "aws:time-zone/@abbrv") : "CST"; final GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone(tz)); cal.set(Calendar.YEAR, WeatherBugDataUtils.getInt(timestampElem, "aws:year/@number", -1)); cal.set(Calendar.MONTH, WeatherBugDataUtils.getInt(timestampElem, "aws:month/@number", -1) - 1); //zero based in GregorianCal cal.set(Calendar.DAY_OF_MONTH, WeatherBugDataUtils.getInt(timestampElem, "aws:day/@number", -1)); cal.set(Calendar.HOUR_OF_DAY, WeatherBugDataUtils.getInt(timestampElem, "aws:hour/@hour-24", -1)); cal.set(Calendar.MINUTE, WeatherBugDataUtils.getInt(timestampElem, "aws:minute/@number", 0)); cal.set(Calendar.SECOND, WeatherBugDataUtils.getInt(timestampElem, "aws:second/@number", 0)); cal.set(Calendar.MILLISECOND, 0); return new Timestamp(cal.getTimeInMillis()); }
From source file:com.projity.util.DateTime.java
public static long hour24() { GregorianCalendar cal = DateTime.calendarInstance(); cal.setTimeInMillis(0);/*w w w .jav a2 s . c om*/ cal.set(GregorianCalendar.HOUR_OF_DAY, 24); return cal.getTimeInMillis(); }
From source file:edu.stanford.muse.email.CalendarUtil.java
public static Date convertYYMMDDToDate(int y, int m, int d, boolean beginning_of_day) { // if m is out of range, its equiv to 0 if (m < 0 || m > 11) m = 0;//from w w w .ja va 2 s . c o m if (d < 0 || d > 30) d = 0; GregorianCalendar c = new GregorianCalendar(); c.set(Calendar.YEAR, y); c.set(Calendar.MONTH, m); c.set(Calendar.DATE, d); if (beginning_of_day) { c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); } else { c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); } return c.getTime(); }
From source file:org.vanbest.xmltv.ZiggoGids.java
public static URL programmeUrl(Channel channel, int day, int hour, int period) throws Exception { StringBuilder s = new StringBuilder(epg_data_root); s.append("?channelIDs="); s.append(channel.id);//ww w .j a v a2 s. c o m GregorianCalendar cal = new GregorianCalendar(); cal.add(Calendar.DAY_OF_MONTH, day); cal.set(Calendar.HOUR_OF_DAY, hour); cal.set(Calendar.MINUTE, 0); String date = new SimpleDateFormat("yyyy-MM-dd+HH").format(cal.getTime()); s.append("&date=" + date); s.append("&period=" + period); return new URL(s.toString()); }