List of usage examples for java.util GregorianCalendar getTimeInMillis
public long getTimeInMillis()
From source file:edu.lternet.pasta.portal.statistics.GrowthStats.java
private ArrayList<String> buildLabels(GregorianCalendar start, GregorianCalendar end, int scale) { ArrayList<String> labels = new ArrayList<String>(); GregorianCalendar lower = (GregorianCalendar) start.clone(); GregorianCalendar upper = new GregorianCalendar(); GregorianCalendar split = new GregorianCalendar(); while (lower.getTimeInMillis() <= end.getTimeInMillis()) { upper.setTime(lower.getTime());/*from ww w. j ava 2 s. com*/ upper.add(scale, 1); split.setTime( new Date(lower.getTimeInMillis() + (upper.getTimeInMillis() - lower.getTimeInMillis()) / 2)); /* System.out.printf("%s-%s-%s%n", lower.getTime().toString(), split.getTime().toString(), upper.getTime().toString()); */ labels.add(getLabel(scale, split)); lower.setTime(upper.getTime()); } return labels; }
From source file:org.opensaml.util.http.HttpResource.java
/** {@inheritDoc} */ public long getLastModifiedTime() throws ResourceException { try {//from www . j a va 2 s .c o m final Date lastModDate = DateUtils.parseDate(cachedResourceLastModified); final GregorianCalendar cal = new GregorianCalendar(); cal.setTime(lastModDate); return cal.getTimeInMillis(); } catch (DateParseException e) { throw new ResourceException( "Unable to parse " + cachedResourceLastModified + " from HTTP last modified header", e); } }
From source file:de.ribeiro.android.gso.core.UntisProvider.java
/** * Synchronisiert alle verfgbaren WeekDatas im Stupid * * @param logger/*from www. j av a 2 s . c om*/ * @param selectedStringDate * @param selectedElement * @param myType * @param htmlResponse * @param stupid * @return * @throws Exception */ public static List<ICalEvent> syncWeekData(GregorianCalendar gc, String selectedElement, Type myType, HtmlResponse htmlResponse, Stupid stupid) throws Exception { List<ICalEvent> result = new ArrayList<ICalEvent>(); int currentDayOfWeek = gc.get(Calendar.DAY_OF_WEEK); // den currentDay auf den folge Montag setzen if (currentDayOfWeek < 2) { // 1000*60*60*24 = 1 Tag! gc.setTimeInMillis(gc.getTimeInMillis() + (1000 * 60 * 60 * 24 * (2 - currentDayOfWeek))); } if (currentDayOfWeek > 6) { // 1000*60*60*24 = 1 Tag! gc.setTimeInMillis(gc.getTimeInMillis() + (1000 * 60 * 60 * 24 * 2)); } String date = ConvertToStupidDateString(gc); String selectedType = myType.type; String selectedClassIndex = getIndexOfSelectorValue(myType.elementList, selectedElement); if (selectedClassIndex == "-1" || selectedType.equalsIgnoreCase("")) { throw new Exception(selectedElement + " kann nicht synchronisiert werden! " + selectedElement + " wurde nicht in der Liste der verfgbaren Elemente gefunden!"); } while (selectedClassIndex.length() < 3) { selectedClassIndex = "0" + selectedClassIndex; } WeekData weekData = new WeekData(stupid); try { // URL setzten URL url = new URL( "https://webuntis.stadt-koeln.de/WebUntis/Ical.do?school=K175055&ajaxCommand=renderTimetable&rpt_sd=" + date + "&type=" + 1 + "&elemId=" + selectedClassIndex + "&elemType=" + selectedType); htmlResponse.dataReceived = false; htmlResponse.xmlContent = XmlOPs.readFromURL(url, Const.CONNECTIONTIMEOUT); if (htmlResponse.xmlContent.length() < 50) { // ende return null; } _logger.Info("Week downloaded!"); List<ICalEvent> events = Ical.Parse(htmlResponse.xmlContent); weekData.syncTime = new GregorianCalendar().getTimeInMillis(); weekData.addParameter("syncTime", String.valueOf(weekData.syncTime)); weekData.date = (Calendar) gc.clone(); weekData.elementId = selectedElement; weekData.addParameter("classId", selectedElement); weekData.events = events; weekData.weekId = String.valueOf(gc.get(Calendar.WEEK_OF_YEAR)); weekData.addParameter("weekId", weekData.weekId); weekData.typeId = myType.type; weekData.addParameter("typeId", weekData.typeId); weekData.weekDataVersion = "2"; weekData.addParameter("weekDataVersion", weekData.weekDataVersion); // stupid.stupidData.add(wd); } catch (Exception e) { throw e; } // prfen, ob bereits die Woche fr die Klasse und den typ vorliegt: WeekData existWeekData = null; // alle bestehden Wochen abrufen: for (int y = 0; y < stupid.stupidData.size(); y++) { existWeekData = stupid.stupidData.get(y); // prfen, ob das bestehende Element, dem neu hinzuzufgenden // entspricht(klasse,KW,Typ) if (existWeekData.elementId.equalsIgnoreCase(weekData.elementId) && existWeekData.weekId.equalsIgnoreCase(weekData.weekId) && existWeekData.typeId.equalsIgnoreCase(weekData.typeId)) { // ja,es ist eine gleiche Woche bereits vorhanden // jedes event der neuen woche prfen, ob dieses schon existiert for (int ev = 0; ev < weekData.events.size(); ev++) { ICalEvent newevent = weekData.events.get(ev); // die schulstunde vom neuen event heraussuchen int schulstunde = GetSchulstundeOfEvent(newevent); // damit die schulstunde vom bestenden stundeplan abrufen ICalEvent existingevent = GetSchulstunde(existWeekData, newevent.DTSTART.get(Calendar.DAY_OF_WEEK), schulstunde); if (existingevent != null) newevent.UID = existingevent.UID; // beide schulstunden vergleichen if (compareEvents(existingevent, newevent)) { // unterschiede gefunden newevent.UID = "diff"; if (existingevent == null) _logger.Info("Es wurden Unterschiede in den Events gefunden: Neues Event " + newevent.DESCRIPTION + " , " + newevent.SUMMARY + " , kein altes Event vorhanden!"); else { _logger.Info("Es wurden Unterschiede in den Events gefunden: Neues Event " + newevent.DESCRIPTION + " , " + newevent.SUMMARY + " , Altes Event " + existingevent.DESCRIPTION + " , " + existingevent.SUMMARY); } // ber unterschiede benachrichtigen result.add(newevent); } // das existierende event aus dem datensatz lschen existWeekData.events.remove(existingevent); } for (ICalEvent event : existWeekData.events) { event.UID = "deleted"; weekData.events.add(event); } // alle verbleibenden events aus dem existierenden datensatz // sind ausgefallene stunden // existiert schon...ersetzen weekData.isDirty = true; stupid.stupidData.set(y, weekData); return SummarizeChanges(result); } } stupid.stupidData.add(weekData); // fgt die geparste Woche den // // Hauptdaten // // hinzu stupid.sort(); return SummarizeChanges(result); }
From source file:org.apache.eagle.jpm.mr.history.MRHistoryJobDailyReporter.java
@Override protected void runOneIteration() throws Exception { GregorianCalendar calendar = new GregorianCalendar(timeZone); int currentHour = calendar.get(Calendar.HOUR_OF_DAY); long currentTimestamp = calendar.getTimeInMillis(); if (!isSentHour(currentHour)) { isDailySent = false;//from ww w. j av a2 s . c o m } else if (!isDailySent) { isDailySent = true; LOG.info("last job report time is {} %s", DateTimeUtil.millisecondsToHumanDateWithSeconds(lastSentTime), timeZone.getID()); try { Collection<String> sites = loadSites(APP_TYPE); if (sites == null || sites.isEmpty()) { LOG.warn("application MR_HISTORY_JOB_APP does not run on any sites!"); return; } for (String site : sites) { int reportHour = currentHour / dailySentPeriod * dailySentPeriod; calendar.set(Calendar.HOUR_OF_DAY, reportHour); long endTime = calendar.getTimeInMillis() / DateTimeUtil.ONEHOUR * DateTimeUtil.ONEHOUR; long startTime = endTime - DateTimeUtil.ONEHOUR * dailySentPeriod; String subject = buildAlertSubject(site, startTime, endTime); Map<String, Object> alertData = buildAlertData(site, startTime, endTime); sendByEmailWithSubject(alertData, subject); } } catch (Exception ex) { LOG.error("Fail to get job summery info due to {}", ex.getMessage(), ex); } lastSentTime = currentTimestamp; } }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations.FetchActivityOperation.java
private void saveLastSyncTimestamp(@NonNull GregorianCalendar timestamp) { SharedPreferences.Editor editor = GBApplication.getPrefs().getPreferences().edit(); editor.putLong(getLastSyncTimeKey(), timestamp.getTimeInMillis()); editor.apply();/* ww w .j a va2 s . c o m*/ }
From source file:op.tools.SYSCalendar.java
/** * nimmt das bergebene Datum und setzt die Uhrzeitkomponente auf 00:00:00. * * @param d/*from w ww.j a v a 2 s . com*/ * @return das Ergebnis als TimeInMillis */ public static long startOfDay(Date d) { GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(d.getTime()); gc.set(GregorianCalendar.HOUR_OF_DAY, 0); gc.set(GregorianCalendar.MINUTE, 0); gc.set(GregorianCalendar.SECOND, 0); gc.set(GregorianCalendar.MILLISECOND, 0); return gc.getTimeInMillis(); }
From source file:org.apache.chemistry.opencmis.server.impl.atompub.AtomDocumentBase.java
/** * Writes a simple date tag.//ww w . j ava 2 s . com */ public void writeSimpleDate(String namespace, String name, GregorianCalendar value) throws XMLStreamException { if (value == null) { return; } writeSimpleTag(namespace, name, formatDate(value.getTimeInMillis())); }
From source file:op.tools.SYSCalendar.java
/** * nimmt das bergebene Datum und setzt die Uhrzeitkomponente auf 23:59:59 * * @param d/* w w w . j a v a 2 s . c o m*/ * @return das Ergebnis als TimeInMillis */ public static long endOfDay(Date d) { GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(d.getTime()); gc.set(GregorianCalendar.HOUR_OF_DAY, 23); gc.set(GregorianCalendar.MINUTE, 59); gc.set(GregorianCalendar.SECOND, 59); gc.set(GregorianCalendar.MILLISECOND, 0); return gc.getTimeInMillis(); }
From source file:org.sakaiproject.nakamura.cluster.ClusterTrackingServiceImpl.java
public ClusterTrackingServiceImpl() { GregorianCalendar calendar = new GregorianCalendar(2009, 8, 22); epoch = calendar.getTimeInMillis(); }
From source file:org.apache.juddi.mapping.MappingApiToModel.java
/** * * @param apiSubscription// w w w .j a v a 2s. c om * @param modelSubscription * @throws DispositionReportFaultMessage */ public static void mapSubscription(org.uddi.sub_v3.Subscription apiSubscription, org.apache.juddi.model.Subscription modelSubscription) throws DispositionReportFaultMessage { modelSubscription.setSubscriptionKey(apiSubscription.getSubscriptionKey()); modelSubscription.setBindingKey(apiSubscription.getBindingKey()); if (apiSubscription.getNotificationInterval() != null) { modelSubscription.setNotificationInterval(apiSubscription.getNotificationInterval().toString()); } modelSubscription.setMaxEntities(apiSubscription.getMaxEntities()); if (apiSubscription.getExpiresAfter() != null) { GregorianCalendar gc = apiSubscription.getExpiresAfter().toGregorianCalendar(); modelSubscription.setExpiresAfter(new Date(gc.getTimeInMillis())); } if (apiSubscription.isBrief() != null) { modelSubscription.setBrief(apiSubscription.isBrief()); } else { modelSubscription.setBrief(Boolean.FALSE); } String rawFilter = JAXBMarshaller.marshallToString( new ObjectFactory().createSubscriptionFilter(apiSubscription.getSubscriptionFilter()), "org.uddi.sub_v3"); logger.debug("marshalled subscription filter: " + rawFilter); modelSubscription.setSubscriptionFilter(rawFilter); }