List of usage examples for java.util GregorianCalendar getTimeInMillis
public long getTimeInMillis()
From source file:org.apache.eagle.jpm.mr.history.metrics.JobCountMetricsGenerator.java
private GenericMetricEntity generateEntity(GregorianCalendar calendar, String state, int count) { GenericMetricEntity metricEntity = new GenericMetricEntity(); metricEntity.setTimestamp(calendar.getTimeInMillis()); metricEntity.setPrefix(String.format(Constants.HADOOP_HISTORY_TOTAL_METRIC_FORMAT, Constants.JOB_LEVEL, Constants.JOB_COUNT_PER_DAY)); metricEntity.setValue(new double[] { count }); @SuppressWarnings("serial") Map<String, String> baseTags = new HashMap<String, String>() { {/*from ww w . j a va2s. c om*/ put("site", appConfig.getJobHistoryEndpointConfig().site); put(MRJobTagName.JOB_STATUS.toString(), state); } }; metricEntity.setTags(baseTags); return metricEntity; }
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);/* w w w. jav a2 s . c o m*/ 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 { 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:op.tools.SYSCalendar.java
public static String toGermanTime(GregorianCalendar gc) { Date date = new Date(gc.getTimeInMillis()); Format formatter;/*from www . jav a 2 s. com*/ formatter = new SimpleDateFormat("HH:mm"); return formatter.format(date); }
From source file:Controllers.CompteController.java
@RequestMapping(value = "validation", method = RequestMethod.POST) public ModelAndView inscription(HttpServletRequest request, HttpServletResponse response) throws Exception { // Cration du modelAndView de la page de connexion ModelAndView mv = new ModelAndView("connexion"); // Rcupration des donnes String result;// ww w. j a v a 2 s. co m String nom = request.getParameter("nom"); String prenom = request.getParameter("prenom"); String login = request.getParameter("login"); String password = request.getParameter("password"); String mail = request.getParameter("mail"); String age = request.getParameter("ddn"); // Vrification de la validit des donnes if (login.isEmpty() || password.isEmpty() || mail.isEmpty() || nom.isEmpty() || prenom.isEmpty()) { // Si les champs sont mal remplis, // on raffiche la page d'inscription mv = new ModelAndView("inscription"); result = "Veuillez renseigner tous les champs..."; mv.addObject("inscriptionMessage", result); return mv; } // Calcul de l'age de la personne Integer ageInscription = null; if (age != null && age.length() != 0) { SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy"); // A faire : Vrification des paramtres. GregorianCalendar gcBirth = new GregorianCalendar(Integer.parseInt(age.split("/")[2]), Integer.parseInt(age.split("/")[1]) - 1, Integer.parseInt(age.split("/")[0])); GregorianCalendar now = new GregorianCalendar(); long diff = now.getTimeInMillis() - gcBirth.getTimeInMillis(); ageInscription = now.get(Calendar.YEAR) - gcBirth.get(Calendar.YEAR); } // Gestion des doublons if (profilService.exists(login)) { mv = new ModelAndView("inscription"); result = "Le login " + login + " existe dj! veuillez le changer"; mv.addObject("inscriptionMessage", result); return mv; } else { // Ajout de la personne inscriptionService.add(nom, prenom, login, password, mail, ageInscription); result = "Vous vous tes bien inscrit, veuillez vous connecter"; mv.addObject("inscriptionMessage", result); return mv; } }
From source file:op.tools.SYSCalendar.java
/** * Generates an ArrayList of Dates. Stepping through the day in 15 minutes steps like {"17:00","17:15"...} * Der verwendete Datentyp ist GregorianCalendar *//*from www . j av a 2 s . co m*/ public static ArrayList<Date> getTimeList() { ArrayList list = new ArrayList(); GregorianCalendar gc = today(); for (int i = 1; i <= 96; i++) { list.add(new Date(gc.getTimeInMillis())); gc.add(GregorianCalendar.MINUTE, 15); } return list; }
From source file:op.tools.SYSCalendar.java
/** * Addiert (bzw. Subtrahiert) eine angebenene Anzahl von Tagen auf das (bzw. von dem) * bergebenen Datum und gibt es dann zurck. * * @param date - Ausgangsdatum//from ww w . j a v a 2 s . c o m * @param numDays - Anzahl der Tage die addiert bzw. subtrahiert werdenn sollen. * @return neues Datum */ public static Date addDate(Date date, int numDays) { GregorianCalendar gc = toGC(date); gc.add(GregorianCalendar.DATE, numDays); return new Date(gc.getTimeInMillis()); }
From source file:uk.nhs.cfh.dsp.srth.demographics.person.utils.PatientUtilsServiceImpl.java
public Patient createRandomPatient(int minAge) { GregorianCalendar gc = new GregorianCalendar(1900, 0, 1); long centuryStart = gc.getTimeInMillis(); // rewind time to now - 1 GregorianCalendar gc2 = new GregorianCalendar(); gc2.setTime(Calendar.getInstance().getTime()); gc2.add(Calendar.YEAR, -minAge); long todayMinusMinYears = gc2.getTimeInMillis(); // use a random value to generate values between century start and today long randomTime = (long) (Math.random() * (todayMinusMinYears - centuryStart)) + centuryStart; // use random time to set calendar gc.setTimeInMillis(randomTime);//from ww w . j ava 2 s . c o m // create and return patient with dob as random time return createRandomPatient(gc); }
From source file:eu.tango.energymodeller.energypredictor.AveragePowerEnergyPredictor.java
/** * This looks at historic information and gets the average power * consumption.//from www . jav a 2 s .c o m * * @param host The host to get the average power for * @param duration The time in seconds before now to get the average for * @return The average power of the host */ private double getAverageHostPower(Host host, long duration) { double answer = 0; double count = 0; /** * The period of time is so short so average measured power values. * Not considering individual time periods, that each measurement lasted * for. i.e. assume a regular arrival rate. */ GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(cal.getTimeInMillis() - TimeUnit.SECONDS.toMillis(duration)); TimePeriod timePeriod = new TimePeriod(cal, duration); List<HostEnergyRecord> data = database.getHostHistoryData(host, timePeriod); for (int i = 0; i <= data.size() - 2; i++) { HostEnergyRecord power = data.get(i); answer = answer + power.getPower(); count = count + 1; } if (count == 0) { return 0.0; } return answer / count; }
From source file:op.tools.SYSCalendar.java
public static String toAnsi(GregorianCalendar gc) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date d = new Date(gc.getTimeInMillis()); return sdf.format(d); }
From source file:org.openplans.delayfeeder.RouteStatus.java
private RouteFeedItem getLatestItem(String agency, String route, Session session) { RouteFeed feed = getFeed(agency, route, session); if (feed == null) { return null; }// w w w .j a v a2s . c om GregorianCalendar now = new GregorianCalendar(); if (feed.lastFetched == null || now.getTimeInMillis() - feed.lastFetched.getTimeInMillis() > FEED_UPDATE_FREQUENCY) { try { refreshFeed(feed, session); } catch (Exception e) { e.printStackTrace(); logger.warn(e.fillInStackTrace()); } } Set<RouteFeedItem> list = feed.items; if (list.size() == 0) { return null; } RouteFeedItem item = (RouteFeedItem) list.toArray()[0]; return item; }