List of usage examples for java.util GregorianCalendar setTime
public final void setTime(Date date)
Date
. From source file:DateUtility.java
public static boolean isToday(Date date) { GregorianCalendar now = new GregorianCalendar(); GregorianCalendar then = new GregorianCalendar(); then.setTime(date); return isSameDay(now, then); }
From source file:org.roda_project.commons_ip.utils.Utils.java
public static XMLGregorianCalendar getCurrentCalendar() throws DatatypeConfigurationException { GregorianCalendar gcal = new GregorianCalendar(); gcal.setTime(new Date()); return DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal); }
From source file:org.finra.dm.core.DmDateUtils.java
/** * Gets an instance of XMLGregorianCalendar class initialized per the specified java.util.Date value. Returns the current date/time if date is null. * * @param date the java.util.Date value to be converted into XMLGregorianCalendar. * * @return the XMLGregorianCalendar instance initialized per specified date value */// w ww. jav a2 s . c o m public static XMLGregorianCalendar getXMLGregorianCalendarValue(Date date) { GregorianCalendar gregorianCalendar = new GregorianCalendar(); if (date != null) { gregorianCalendar.setTime(date); } try { return DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar); } catch (DatatypeConfigurationException ex) { throw new IllegalStateException("Failed to create a new instance of DataTypeFactory.", ex); } }
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 ww. j av a2s. 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:DateUtils.java
public static final String formatDate(Date dt, String format) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(dt); java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(format); sdf.setTimeZone(TimeZone.getDefault()); return (sdf.format(cal.getTime())); }
From source file:DateUtility.java
/** * This will retun the first millisecond of the month * that contains the timestamp provided//from w w w .j a v a 2 s .c o 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:de.arago.rike.zombie.ZombieHelper.java
static String toPrettyJSON(List ticks) { List<OverdueMilestone> milestones = getOverdueMilestones(true); Collections.sort(milestones, new DoneSorter()); final List data = new ArrayList(); final Map open = new HashMap(); final Map in_progress = new HashMap(); final Map done = new HashMap(); data.add(open);/* w w w. j av a2s . co m*/ data.add(in_progress); data.add(done); open.put("Label", "open"); open.put("color", "red"); in_progress.put("Label", "in_progress"); in_progress.put("color", "yellow"); done.put("Label", "done"); done.put("color", "green"); List openData = new ArrayList(); List in_progressData = new ArrayList(); List doneData = new ArrayList(); open.put("data", openData); in_progress.put("data", in_progressData); done.put("data", doneData); long now = new Date().getTime(); int i = 1; for (OverdueMilestone o : milestones) { Milestone stone = o.getMilestone(); ticks.add("<a href='/web/guest/rike/-/show/milestone/" + stone.getId() + "'>" + StringEscapeUtils.escapeHtml(stone.getTitle()) + "</a>"); GregorianCalendar c = new GregorianCalendar(); c.setTime(stone.getDueDate()); c.add(Calendar.HOUR_OF_DAY, -((o.getWorkLeftInHours() - o.getWorkInProgressInHours()) * 7 * 24) / stone.getPerformance()); long time1 = c.getTimeInMillis(); c.add(Calendar.HOUR_OF_DAY, -(o.getWorkInProgressInHours() * 7 * 24) / stone.getPerformance()); long time2 = c.getTimeInMillis(); c.add(Calendar.HOUR_OF_DAY, -(o.getWorkDoneInHours() * 7 * 24) / stone.getPerformance()); long time3 = c.getTimeInMillis(); List item = new ArrayList(); item.add(time1); item.add(i); item.add(stone.getDueDate().getTime()); item.add(""); openData.add(item); item = new ArrayList(); item.add(time2); item.add(i); item.add(time1); item.add(""); in_progressData.add(item); item = new ArrayList(); item.add(time3); item.add(i); item.add(time2); item.add(""); doneData.add(item); ++i; } return JSONArray.toJSONString(data); }
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 a 2 s. co 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:DateUtils.java
public static final String dateToString(Date dt, String dateformat) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(dt); StringBuffer ret = new StringBuffer(); String separator = new String(); if (dateformat.equals(DateUtils.FORMAT_YYYYMMDD)) { separator = "-"; }/* ww w. ja v a 2s . c om*/ 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:dev.meng.wikipedia.profiler.util.StringUtils.java
public static GregorianCalendar parseTimestamp(String string, String format) throws ParseException { GregorianCalendar result = null; SimpleDateFormat formatter = new SimpleDateFormat(format); result = (GregorianCalendar) GregorianCalendar.getInstance(); result.setTime(formatter.parse(string)); return result; }