List of usage examples for java.util Calendar getTimeInMillis
public long getTimeInMillis()
From source file:com.jxt.web.service.AdminServiceImpl.java
private List<String> filterInactiveAgents(List<String> agentIds, int durationDays) { if (CollectionUtils.isEmpty(agentIds)) { return Collections.emptyList(); }// w w w . j ava 2 s .c o m List<String> inactiveAgentIds = new ArrayList<>(); final long toTimestamp = System.currentTimeMillis(); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, durationDays * -1); final long fromTimestamp = cal.getTimeInMillis(); Range queryRange = new Range(fromTimestamp, toTimestamp); for (String agentId : agentIds) { boolean dataExists = this.agentStatDao.agentStatExists(agentId, queryRange); if (!dataExists) { inactiveAgentIds.add(agentId); } } return inactiveAgentIds; }
From source file:org.openmhealth.shim.fatsecret.FatsecretShim.java
@Override public ShimDataResponse getData(ShimDataRequest shimDataRequest) throws ShimException { long numToSkip = 0; long numToReturn = 3; Calendar cal = Calendar.getInstance(); cal.set(2014, Calendar.AUGUST, 1); Date endDate = new Date(cal.getTimeInMillis()); cal.add(Calendar.DATE, -1);//from w w w .j a v a 2 s . com Date startDate = new Date(cal.getTimeInMillis()); DateTime startTime = new DateTime(startDate.getTime()); DateTime endTime = new DateTime(endDate.getTime()); MutableDateTime epoch = new MutableDateTime(); epoch.setDate(0); int days = 16283; //Days.daysBetween(epoch, new DateTime()).getDays() - 1; String endPoint = "food_entries.get"; String accessToken = shimDataRequest.getAccessParameters().getAccessToken(); String tokenSecret = shimDataRequest.getAccessParameters().getTokenSecret(); URL url = signUrl(DATA_URL + "?date=" + days + "&format=json&method=" + endPoint, accessToken, tokenSecret, null); System.out.println("Signed URL is: \n\n" + url); // Fetch and decode the JSON data. ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonData; HttpGet get = new HttpGet(url.toString()); HttpResponse response; try { response = httpClient.execute(get); HttpEntity responseEntity = response.getEntity(); jsonData = objectMapper.readTree(responseEntity.getContent()); return ShimDataResponse.result(FatsecretShim.SHIM_KEY, jsonData); } catch (IOException e) { throw new ShimException("Could not fetch data", e); } finally { get.releaseConnection(); } }
From source file:com.tesora.dve.db.mysql.common.MysqlAPIUtils.java
/** * Methods to read and write length coded times in the Binary Protocol * /* www . j a v a 2 s . c om*/ * if days, hours, minutes, seconds and micro_seconds are all 0, length is 0 * and no other field is sent * * if micro_seconds is 0, length is 8 and micro_seconds is not sent * otherwise length is 12 * * Fields * length (1) -- number of bytes following (valid values: 0, 8, 12) * is_negative (1) -- (1 if minus, 0 for plus) * days (4) -- days * hours (1) -- hours * minutes (1) -- minutes * seconds (1) -- seconds * micro_seconds (4) -- micro-seconds */ public static Time getLengthCodedTime(ByteBuf cb) throws PEException { Calendar cal = Calendar.getInstance(); cal.clear(); short length = cb.readUnsignedByte(); if (length == 0) return null; Time ret = null; if (length >= 8) { cb.skipBytes(1); // this is the sign - we are ignoring this for now cb.skipBytes(4); // this is "days" - we are ignoring this for now cal.set(Calendar.HOUR_OF_DAY, cb.readByte()); cal.set(Calendar.MINUTE, cb.readByte()); cal.set(Calendar.SECOND, cb.readByte()); if (length == 12) { long microSeconds = cb.readUnsignedInt(); cal.set(Calendar.MILLISECOND, (int) (microSeconds / 1000)); } if (length > 12) { throw new PEException("Invalid length specified to date type (" + length + ")"); } ret = new Time(cal.getTimeInMillis()); } return ret; }
From source file:com.alkacon.opencms.usagereport.CmsUsageReportJob.java
/** * @see org.opencms.scheduler.I_CmsScheduledJob#launch(org.opencms.file.CmsObject, java.util.Map) *///from w w w. j a va 2s . co m public String launch(CmsObject cms, Map parameters) throws Exception { // read the job parameter for the hours to include the resources for the report int hours = DEFAULT_HOURS; String hourStr = (String) parameters.get(PARAM_HOURS); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(hourStr)) { try { hours = Integer.parseInt(hourStr); } catch (NumberFormatException ex) { // noop -> use default amount } } // read all resources which are modified after the given time // which can be new or modified resources Calendar cal = new GregorianCalendar(); cal.add(Calendar.HOUR_OF_DAY, hours * -1); long time = cal.getTimeInMillis(); List resources = cms.readResources(cms.getRequestContext().getUri(), CmsResourceFilter.DEFAULT.addRequireFile().addRequireLastModifiedAfter(time), true); List newResources = new ArrayList(); List changedResources = new ArrayList(); // separate new/changed Iterator iter = resources.iterator(); while (iter.hasNext()) { CmsResource res = (CmsResource) iter.next(); if (res.getDateCreated() >= time) { newResources.add(res); } else { changedResources.add(res); } } // sort the lists Collections.sort(newResources, new CmsDateResourceComparator(cms, Arrays.asList(new String[] { "dateCreated" }), false)); Collections.sort(changedResources, new CmsDateResourceComparator(cms, Arrays.asList(new String[] { "dateLastModified" }), false)); // send notification mail if ((newResources.size() > 0) || (changedResources.size() > 0)) { try { CmsUsageReportNotification notification = new CmsUsageReportNotification(cms, cms.getRequestContext().currentUser(), newResources, changedResources); notification.addMacro("hours", String.valueOf(hours)); notification.send(); } catch (Exception ex) { String msg = Messages.get().getBundle().key(Messages.ERR_SEND_MAIL_1, cms.getRequestContext().currentUser().getEmail()); if (LOG.isErrorEnabled()) { LOG.error(msg, ex); } return msg; } return Messages.get().getBundle().key(Messages.LOG_SEND_MAIL_SUCCESS_1, cms.getRequestContext().currentUser().getEmail()); } return Messages.get().getBundle().key(Messages.LOG_NO_RESOURCES_FOR_REPORT_0); }
From source file:com.eryansky.common.utils.DateUtil.java
/** * // w ww.ja v a 2 s . c o m * ??? ? 2008-08-08 16:16:34 */ public static String addHours(String startDate, int intHour) { try { DateFormat df = DateFormat.getDateTimeInstance(); Date date = df.parse(startDate); Calendar cal = Calendar.getInstance(); cal.setTime(date); long longMills = cal.getTimeInMillis() + intHour * 60 * 60 * 1000; cal.setTimeInMillis(longMills); // return df.format(cal.getTime()); } catch (Exception Exp) { return null; } }
From source file:com.eryansky.common.utils.DateUtil.java
/** * /*from ww w . ja v a2 s . c o m*/ * ???? ? 2008-08-08 16:16:34 */ public static String delHours(String startDate, int intHour) { try { DateFormat df = DateFormat.getDateTimeInstance(); Date date = df.parse(startDate); Calendar cal = Calendar.getInstance(); cal.setTime(date); long longMills = cal.getTimeInMillis() - intHour * 60 * 60 * 1000; cal.setTimeInMillis(longMills); // return df.format(cal.getTime()); } catch (Exception Exp) { return null; } }
From source file:com.navercorp.pinpoint.web.service.AdminServiceImpl.java
private List<String> filterInactiveAgents(List<String> agentIds, int durationDays) { if (CollectionUtils.isEmpty(agentIds)) { return Collections.emptyList(); }/*from w w w. ja v a 2 s.co m*/ List<String> inactiveAgentIds = new ArrayList<>(); final long toTimestamp = System.currentTimeMillis(); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, durationDays * -1); final long fromTimestamp = cal.getTimeInMillis(); Range queryRange = new Range(fromTimestamp, toTimestamp); for (String agentId : agentIds) { // FIXME This needs to be done with a more accurate information. // If at any time a non-java agent is introduced, or an agent that does not collect jvm data, // this will fail boolean dataExists = this.jvmGcDao.agentStatExists(agentId, queryRange); if (!dataExists) { inactiveAgentIds.add(agentId); } } return inactiveAgentIds; }
From source file:gxu.software_engineering.market.android.service.SyncService.java
@Override protected void onHandleIntent(Intent intent) { // ??/*w w w .j a va2 s . co m*/ if (!NetworkUtils.connected(getApplicationContext())) { return; } // ?? long lastSyncMills = app.getPrefs().getLong(C.LAST_SYNC, 0); if (lastSyncMills == 0L) { Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, 1980); lastSyncMills = c.getTimeInMillis(); } String uri = C.DOMAIN + String.format("/sync?count=%d&last=%s", C.DEFAULT_LIST_SIZE, lastSyncMills); JSONObject result = null; try { result = RESTMethod.get(uri); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } boolean nice = false; ContentValues[] categories = null; ContentValues[] users = null; ContentValues[] items = null; try { if (result.getInt(C.STATUS) == C.OK) { nice = true; categories = Processor.toCategories(result.getJSONArray(C.CATEGORIES)); users = Processor.toUsers(result.getJSONArray(C.USERS)); items = Processor.toItems(result.getJSONArray(C.ITEMS)); } else { throw new RuntimeException(result.getString(C.MSG)); } } catch (Exception e) { Log.wtf("synv json result error!", e); final String msg = e.getMessage(); handler.post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), getResources().getString(R.string.sync_error, msg), Toast.LENGTH_SHORT).show(); } }); } if (nice) { getContentResolver().bulkInsert(Uri.parse(C.BASE_URI + C.CATEGORIES), categories); getContentResolver().bulkInsert(Uri.parse(C.BASE_URI + C.USERS), users); getContentResolver().bulkInsert(Uri.parse(C.BASE_URI + C.ITEMS), items); final long now = System.currentTimeMillis(); // app.getPrefs().edit().putLong(C.LAST_SYNC, now).commit(); // ???? handler.post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), getResources().getString(R.string.sync_nice, DateUtils.getRelativeTimeSpanString(now)), Toast.LENGTH_SHORT).show(); } }); } }
From source file:com.amediamanager.util.S3FormSigner.java
/** * The UploadPolicy method creates the S3 upload policy for the aMediaManager application. * Much of this is hard coded and would have to change with any changes to the fields in the S3 * upload form./* w ww .j a v a 2 s. c o m*/ * * @param key this is not currently used. * @param redirectUrl this is the URL to which S3 will redirect the browser on successful upload. * @return the upload policy string is returned. */ String generateUploadPolicy(String s3BucketName, String keyPrefix, AWSCredentialsProvider credsProvider, String redirectUrl) { Calendar dateTime = Calendar.getInstance(); // add the offset from UTC dateTime.add(Calendar.MILLISECOND, -dateTime.getTimeZone().getOffset(dateTime.getTimeInMillis())); // add 15 minutes more for skew dateTime.add(Calendar.MINUTE, 15); SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); String expirationDate = dateFormatter.format(dateTime.getTime()); StringBuilder sb = new StringBuilder(); sb.append("{ \"expiration\": \"" + expirationDate + "\","); sb.append("\"conditions\": [ { \"bucket\": \"" + s3BucketName + "\" }, "); sb.append("[\"starts-with\", \"$key\", \"" + keyPrefix + "/\"], "); sb.append("{ \"success_action_redirect\": \"" + redirectUrl + "\" },"); sb.append("[\"eq\", \"$x-amz-meta-bucket\", \"" + s3BucketName + "\"], "); sb.append("[\"starts-with\", \"$x-amz-meta-owner\", \"\"], "); sb.append("[\"starts-with\", \"$x-amz-meta-uuid\", \"\"], "); sb.append("[\"starts-with\", \"$x-amz-meta-title\", \"\"], "); sb.append("[\"starts-with\", \"$x-amz-meta-tags\", \"\"], "); sb.append("[\"starts-with\", \"$x-amz-meta-createdDate\", \"\"], "); sb.append("[\"starts-with\", \"$x-amz-meta-description\", \"\"], "); sb.append("[\"starts-with\", \"$x-amz-meta-privacy\", \"\"], "); sb.append("[\"starts-with\", \"$Content-Type\", \"video/\"], "); if (credsProvider.getCredentials() instanceof BasicSessionCredentials) { sb.append("[\"starts-with\", \"$x-amz-security-token\", \"\"], "); } sb.append("[\"content-length-range\", 0, 1073741824] ] }"); return sb.toString(); }
From source file:net.sf.dynamicreports.test.jasper.chart.DifferenceChartTest.java
@Override protected JRDataSource createDataSource() { DRDataSource dataSource = new DRDataSource("field1", "field2", "field3", "field4"); Calendar c = Calendar.getInstance(); c.setTime(new Date()); for (int i = 0; i < 4; i++) { dataSource.add(c.getTime(), new Timestamp(c.getTimeInMillis()), i + 5, 7 - i); c.add(Calendar.DAY_OF_MONTH, 1); }// w w w. j av a2 s .co m return dataSource; }