List of usage examples for java.util Calendar SECOND
int SECOND
To view the source code for java.util Calendar SECOND.
Click Source Link
get
and set
indicating the second within the minute. From source file:DateUtil.java
/** * Returns a Date set to the first possible millisecond of the hour. * If a null day is passed in, a new Date is created. *//*from w ww . j av a 2 s. co m*/ public static Date getStartOfHour(Date day, Calendar cal) { if (day == null) day = new Date(); cal.setTime(day); cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND)); return cal.getTime(); }
From source file:Time.java
public int getSeconds() { return calendar_.get(Calendar.SECOND); }
From source file:com.watchrabbit.crawler.auth.service.AuthServiceImpl.java
@Override public Collection<Cookie> getSession(String domain) { Collection<Cookie> cookies = sessionRepository.findByDomain(domain); if (cookies != null) { return cookies; }/* www. j a v a 2 s . co m*/ RemoteWebDriver driver = remoteWebDriverFactory.produceDriver(); try { AuthData authData = authDataDao.findByDomain(domain); if (authData == null) { LOGGER.info("Cannot find auth data for {}", domain); return emptyList(); } driver.get(authData.getAuthEndpointUrl()); loaderService.waitFor(driver); WebElement loginForm = locateLoginForm(driver); if (loginForm == null) { LOGGER.error("Cannot locate any form that matches criteria on {}", authData.getAuthEndpointUrl()); return emptyList(); } WebElement password = findPasswordInput(loginForm); LOGGER.debug("Found password field with name {}", password.getAttribute("name")); WebElement login = findLoginInput(loginForm); LOGGER.debug("Found login field with name {}", login.getAttribute("name")); login.sendKeys(authData.getLogin()); password.sendKeys(authData.getPassword()); loginForm.submit(); loaderService.waitFor(driver); cookies = driver.manage().getCookies(); Calendar now = clock.getCalendar(); now.add(Calendar.SECOND, authData.getSessionDuration()); sessionRepository.save(domain, cookies, now.getTime()); return cookies; } finally { remoteWebDriverFactory.returnWebDriver(driver); } }
From source file:damo.three.ie.prepay.UpdateService.java
@Override protected void onHandleIntent(Intent intent) { Context context = getApplicationContext(); try {//from w w w .ja v a 2 s.c om Log.d(Constants.TAG, "Fetching usages from service."); UsageFetcher usageFetcher = new UsageFetcher(context, true); JSONArray usages = usageFetcher.getUsages(); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences sharedUsagePref = context.getSharedPreferences("damo.three.ie.previous_usage", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedUsagePref.edit(); editor.putLong("last_refreshed_milliseconds", new DateTime().getMillis()); editor.putString("usage_info", usages.toString()); editor.commit(); // Register alarms for newly refreshed usages in background boolean notificationsEnabled = sharedPref.getBoolean("notification", true); List<UsageItem> usageItems = JSONUtils.jsonToUsageItems(usages); List<BasicUsageItem> basicUsageItems = UsageUtils.getAllBasicItems(usageItems); UsageUtils.registerInternetExpireAlarm(context, basicUsageItems, notificationsEnabled, true); } catch (Exception e) { // Try again at 7pm, unless its past 7pm. Then forget and let tomorrow's alarm do the updating. // Still trying to decide if I need a more robust retry mechanism. Log.d(Constants.TAG, "Caught exception: " + e.getLocalizedMessage()); Calendar calendar = Calendar.getInstance(); if (calendar.get(Calendar.HOUR_OF_DAY) < Constants.HOUR_TO_RETRY) { Log.d(Constants.TAG, "Scheduling a re-try for 7pm"); calendar.set(Calendar.HOUR_OF_DAY, Constants.HOUR_TO_RETRY); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); Intent receiver = new Intent(context, UpdateReceiver.class); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Using different request code to 0 so it won't conflict with other alarm below. PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 3, receiver, PendingIntent.FLAG_UPDATE_CURRENT); // Keeping efficiency in mind: // http://developer.android.com/reference/android/app/AlarmManager.html#ELAPSED_REALTIME am.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent); } } finally { Log.d(Constants.TAG, "Finish UpdateService"); UpdateReceiver.completeWakefulIntent(intent); } }
From source file:com.bstek.dorado.core.el.ExpressionUtilsObject.java
public java.util.Date calculateDate(java.util.Date date, String expression) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*w w w . ja v a 2s .co m*/ if (StringUtils.isNotBlank(expression)) { char fieldChar = 0; int field = 0, offset = 0; boolean offsetFound = false; StringBuffer numText = new StringBuffer(); for (int i = 0, len = expression.length(); i < len; i++) { char c = expression.charAt(i); if (c == ' ' || c == ',' || c == ';') { if (field != 0) { if (numText.length() == 0) { throw new IllegalArgumentException( "Argument missed for Date field \"" + fieldChar + "\"."); } int num = Integer.parseInt(numText.toString()); if (offset == 0) { calendar.set(field, num); } else { calendar.add(field, num * offset); } } fieldChar = 0; field = 0; offset = 0; offsetFound = false; numText.setLength(0); } else if (field == 0) { switch (c) { case 'y': case 'Y': field = Calendar.YEAR; break; case 'M': field = Calendar.MONTH; break; case 'd': field = Calendar.DAY_OF_MONTH; break; case 'h': case 'H': field = Calendar.HOUR_OF_DAY; break; case 'm': field = Calendar.MINUTE; break; case 's': field = Calendar.SECOND; break; case 'z': case 'Z': field = Calendar.MILLISECOND; break; default: throw new IllegalArgumentException("Unknown Date field \"" + c + "\"."); } fieldChar = c; } else if (!offsetFound && numText.length() == 0) { if (c == '+') { offset = 1; offsetFound = true; } else if (c == '-') { offset = -1; offsetFound = true; } } else if (c >= '0' && c <= '9') { numText.append(c); } } if (field != 0) { if (numText.length() == 0) { throw new IllegalArgumentException("Argument missed for Date field \"" + fieldChar + "\"."); } int num = Integer.parseInt(numText.toString()); if (offset == 0) { calendar.set(field, num); } else { calendar.add(field, num * offset); } } } return calendar.getTime(); }
From source file:com.gistlabs.mechanize.cache.inMemory.InMemoryCacheEntry.java
private Date getCacheControlExpiresDate() { String maxage = get("Cache-Control", "max-age", this.response); if (maxage.equals("")) return OLD; int seconds = Integer.parseInt(maxage); Calendar cal = Calendar.getInstance(); cal.setTime(getDate());// w w w .j av a 2 s . co m cal.add(Calendar.SECOND, seconds); return cal.getTime(); }
From source file:av1.model.Processo.java
public void gerarNumeroProcesso() { Calendar calendario = Calendar.getInstance(); this.numeroProcesso = calendario.get(Calendar.YEAR) + "" + calendario.get(Calendar.MONTH + 1) + "" + calendario.get(Calendar.DATE) + "" + calendario.get(Calendar.HOUR_OF_DAY) + "" + calendario.get(Calendar.MINUTE) + "" + calendario.get(Calendar.SECOND) + "" + this.fornecedor.getCNPJ(); this.numeroProcesso = this.numeroProcesso.replaceAll("[^a-zZ-Z1-9 ]", ""); }
From source file:ddf.metrics.reporting.internal.rrd4j.RrdDumper.java
private static String getCalendarTime(long timestamp) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(timestamp * 1000); String calTime = months[calendar.get(Calendar.MONTH)] + " " + calendar.get(Calendar.DATE) + " " + calendar.get(Calendar.YEAR) + " "; calTime += addLeadingZero(calendar.get(Calendar.HOUR_OF_DAY)) + ":"; calTime += addLeadingZero(calendar.get(Calendar.MINUTE)) + ":"; calTime += addLeadingZero(calendar.get(Calendar.SECOND)); return calTime; }
From source file:DateUtil.java
/** Get calendar date. **/ public static Date getCal(int dayOfMonth, int month, int year, int hours, int minutes, int seconds, String timezone) throws Exception { // Create calendar object from date values Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("GMT" + timezone)); cal.set(Calendar.DAY_OF_MONTH, dayOfMonth); cal.set(Calendar.MONTH, month); cal.set(Calendar.YEAR, year); cal.set(Calendar.HOUR_OF_DAY, hours); cal.set(Calendar.MINUTE, minutes); cal.set(Calendar.SECOND, seconds); return cal.getTime(); }