List of usage examples for java.util GregorianCalendar setTimeInMillis
public void setTimeInMillis(long millis)
From source file:TimeLib.java
/** * Get the number of time units between the two given timestamps. * @param t0 the first timestamp (as a long) * @param t1 the second timestamp (as a long) * @param field the time unit to use, one of the {@link java.util.Calendar} * fields, or one of the extended fields provided by this class * (MILLENIUM, CENTURY, or DECADE)./*from w ww . j ava 2 s. c o m*/ * @return the number of time units between the two timestamps */ public static int getUnitsBetween(long t0, long t1, int field) { boolean negative = false; if (t1 < t0) { long tmp = t1; t1 = t0; t0 = tmp; // swap negative = true; } GregorianCalendar gc1 = new GregorianCalendar(); GregorianCalendar gc2 = new GregorianCalendar(); gc1.setTimeInMillis(t0); gc2.setTimeInMillis(t1); // add 2 units less than the estimate to 1st date, // then serially add units till we exceed 2nd date int est = estimateUnitsBetween(t0, t1, field); boolean multiYear = isMultiYear(field); if (multiYear) { gc1.add(Calendar.YEAR, -field * (est - 2)); est = -field * est; } else { gc1.add(field, est - 2); } int f = multiYear ? Calendar.YEAR : field; int inc = multiYear ? -field : 1; for (int i = est - inc;; i += inc) { gc1.add(f, inc); if (gc1.after(gc2)) { return negative ? inc - i : i - inc; } } }
From source file:be.fedict.eid.dss.ws.DSSUtil.java
public static XMLGregorianCalendar toXML(DateTime dateTime) { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(dateTime.getMillis()); return datatypeFactory.newXMLGregorianCalendar(calendar); }
From source file:org.opencms.widgets.CmsCalendarWidget.java
/** * Returns the given timestamp as String formatted in a localized pattern.<p> * /*from w ww. j a v a 2s . com*/ * @param locale the locale for the time format * @param messages the messages that contain the time format definitions * @param timestamp the time to format * * @return the given timestamp as String formatted in a localized pattern */ public static String getCalendarLocalizedTime(Locale locale, CmsMessages messages, long timestamp) { // get the current date & time TimeZone zone = TimeZone.getDefault(); GregorianCalendar cal = new GregorianCalendar(zone, locale); cal.setTimeInMillis(timestamp); // format it nicely according to the localized pattern DateFormat df = new SimpleDateFormat(CmsCalendarWidget .getCalendarJavaDateFormat(messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_DATE_FORMAT_0) + " " + messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_TIME_FORMAT_0))); return df.format(cal.getTime()); }
From source file:com.att.ajsc.csilogging.util.UtilLib.java
public static XMLGregorianCalendar epochToXmlGC(long epoch) { try {/*from ww w. jav a2s .co m*/ DatatypeFactory dtf = DatatypeFactory.newInstance(); GregorianCalendar gcal = new GregorianCalendar(); gcal.setTimeInMillis(epoch); gcal.setTimeZone(TimeZone.getTimeZone("Z")); XMLGregorianCalendar xgc = dtf.newXMLGregorianCalendar(gcal); return xgc; } catch (Exception e) { // Do nothing!!! - return a null; } return null; }
From source file:org.colombbus.tangara.Main.java
private static void checkForUpdate() { Configuration conf = Configuration.instance(); // Check for updates if the feature is enabled in conf if (conf.getInteger("checkUpdate.activation") == 1) { boolean checkUpdate = false; GregorianCalendar today = new GregorianCalendar(); GregorianCalendar lastLaunch = new GregorianCalendar(); lastLaunch.setTimeInMillis(0); Properties properties = conf.loadUpdateProperties(); // Read last Launch date if ((properties != null) && (properties.containsKey("checkUpdate.lastLaunch"))) { String strValue = properties.getProperty("checkUpdate.lastLaunch"); long longValue = Long.parseLong(strValue); lastLaunch.setTimeInMillis(longValue); } else {//www. j a va2 s. c o m LOG.warn("Failed to load lastLaunch property"); properties = new Properties(); } // Write last Launch date properties.setProperty("checkUpdate.lastLaunch", Long.toString(today.getTimeInMillis())); conf.saveUpdateProperties(properties); String intervalText = Configuration.instance().getProperty("checkUpdate.interval"); if (intervalText.equals("ALWAYS")) { checkUpdate = true; } else if (intervalText.equals("WEEK")) { lastLaunch.add(GregorianCalendar.DAY_OF_MONTH, 7); checkUpdate = (today.after(lastLaunch)); } else if (intervalText.equals("MONTH")) { lastLaunch.add(GregorianCalendar.MONTH, 1); checkUpdate = (today.after(lastLaunch)); } if (checkUpdate) { SoftwareUpdate.launchVersionCheck(); } } }
From source file:org.opencds.dss.evaluate.EvaluationImpl.java
/** * // w ww . j a v a2s . c om * @param date as long * @return XMLGregorianCalendar */ private static XMLGregorianCalendar long2Gregorian(long date) { DatatypeFactory dataTypeFactory; try { dataTypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(date); return dataTypeFactory.newXMLGregorianCalendar(gc); }
From source file:com.fluidops.iwb.api.ValueResolver.java
/** * Convert a timestamp like 182843848 to a human-readable date. * /* ww w . j ava 2 s .c o m*/ * @param value * @return */ private static String resolveDateFromTimestamp(String value, long multiplyToMs) { Long t = Long.valueOf(value) * multiplyToMs; GregorianCalendar c = new GregorianCalendar(); c.setTimeInMillis(t); DateFormat df = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss"); return df.format(c.getTime()); }
From source file:com.evolveum.midpoint.util.MiscUtil.java
public static XMLGregorianCalendar asXMLGregorianCalendar(Long timeInMilis) { if (timeInMilis == null || timeInMilis == 0) { return null; } else {//from w w w. j av a 2 s. c om GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(timeInMilis); return df.newXMLGregorianCalendar(gc); } }
From source file:eu.openanalytics.rsb.Util.java
/** * Converts a {@link GregorianCalendar} into a {@link XMLGregorianCalendar} * /*from w w w . j av a 2 s .c om*/ * @param calendar * @return */ public static XMLGregorianCalendar convertToXmlDate(final GregorianCalendar calendar) { final GregorianCalendar zuluDate = new GregorianCalendar(); zuluDate.setTimeZone(TimeZone.getTimeZone("UTC")); zuluDate.setTimeInMillis(calendar.getTimeInMillis()); final XMLGregorianCalendar xmlDate = XML_DATATYPE_FACTORY.newXMLGregorianCalendar(zuluDate); return xmlDate; }
From source file:com.evolveum.midpoint.test.util.TestUtil.java
public static XMLGregorianCalendar currentTime() { // This cannot use XmlTypeConverter as we want to use also in tests that do not depend on prism GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.setTimeInMillis(System.currentTimeMillis()); return getDatatypeFactory().newXMLGregorianCalendar(gregorianCalendar); }