List of usage examples for java.text SimpleDateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:com.persistent.cloudninja.scheduler.PerformanceMonitor.java
@Override public boolean execute() { StopWatch watch = new StopWatch(); try {/*from w w w . j a v a 2s . c o m*/ LOGGER.debug("PerformanceMonitor : Execute"); watch.start(); Date lastReadTime = kpiValueTempDao.getMaxTimestamp(); Date lastBatchTime = null; Calendar calendar = Calendar.getInstance(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); String date = null; if (lastReadTime == null) { date = dateFormat.format(calendar.getTime()); lastReadTime = dateFormat.parse(date); } calendar = Calendar.getInstance(); date = dateFormat.format(calendar.getTime()); Date currentUTCTime = dateFormat.parse(date); List<KpiValueTempEntity> listKpiValueTempEntities = null; while (lastReadTime.getTime() <= currentUTCTime.getTime()) { LOGGER.debug("PerformanceMonitor : Process performance counters"); calendar.setTime(lastReadTime); calendar.add(Calendar.MINUTE, 30); date = dateFormat.format(calendar.getTime()); lastBatchTime = dateFormat.parse(date); WADPerformanceCountersEntity[] arrPerfCounter = storageUtility .getPerfCounterEntities(lastReadTime.getTime(), lastBatchTime.getTime()); listKpiValueTempEntities = convertAzureEntityToDBEntity(arrPerfCounter); kpiValueTempDao.addAll(listKpiValueTempEntities); kpiValueTempDao.executeProcessKpiValues(); LOGGER.debug("PerformanceMonitor : Process complete"); lastReadTime = lastBatchTime; } watch.stop(); taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(), "ProcessPerformanceCounters", ""); LOGGER.debug("PerformanceMonitor : Finish"); } catch (ParseException e) { LOGGER.error(e.getMessage(), e); } return true; }
From source file:com.mercandalli.android.apps.files.user.UserModel.java
public String getAccessPassword() { final Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); final SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US); dateFormatGmt.setTimeZone(TimeZone.getTimeZone("UTC")); String currentDate = dateFormatGmt.format(calendar.getTime()); return HashUtils.sha1(HashUtils.sha1(this.password) + currentDate); }
From source file:de.uzk.hki.da.at.ATSipKeepModDates.java
public void doTest(boolean withCompression) throws Exception { File tarArchive = new File(sourceName + ".tgz"); ArchiveBuilder builder = ArchiveBuilderFactory.getArchiveBuilderForFile(tarArchive); builder.unarchiveFolder(tarArchive, sourceDir); File s1;// www.java 2 s . c o m if (withCompression) { s1 = new File("target/atTargetDir/" + sip + ".tgz"); } else { s1 = new File("target/atTargetDir/" + sip + ".tar"); } File unpackedSip = new File("target/atTargetDir/" + sip); String cmd = "./SipBuilder-Unix.sh -rights=\"" + ATWorkingDirectory.CONTRACT_RIGHT_LICENSED.getAbsolutePath() + "\" -source=\"" + sourceDir.getAbsolutePath() + "/\" -destination=\"" + targetDir.getAbsolutePath() + "/\" -workspace=\"" + workDir.getAbsolutePath() + "/\" -single"; if (!withCompression) { cmd += " -noCompression"; } p = Runtime.getRuntime().exec(cmd, null, new File("target/installation")); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); String s = ""; // read the output from the command System.out.println("Here is the standard output of the command:\n"); while ((s = stdInput.readLine()) != null) { System.out.println(s); } // read any errors from the attempted command System.out.println("Here is the standard error of the command (if any):\n"); while ((s = stdError.readLine()) != null) { System.out.println(s); } assertTrue(s1.exists()); assertFalse(new File(workDir + sip).exists()); // Tests content of the first SIP builder = ArchiveBuilderFactory.getArchiveBuilderForFile(s1); try { builder.unarchiveFolder(s1, targetDir); } catch (Exception e) { throw new RuntimeException("couldn't unpack archive", e); } long moddi; Date modDate; String tagStr; SimpleDateFormat dateForm = new SimpleDateFormat("dd.MM.yyyy"); dateForm.setTimeZone(TimeZone.getTimeZone("GMT")); File file = new File(unpackedSip, "data/unter1/unter2/M00000.jpg"); System.out.println("File:" + file.getAbsolutePath() + " exists:" + file.exists()); moddi = file.lastModified(); modDate = new Date(moddi); tagStr = dateForm.format(modDate); if (!tagStr.equals("21.10.2015")) { System.out.println("Unexpected Date: >" + tagStr + "< Expected: >21.10.2015<"); } assertTrue(tagStr.equals("21.10.2015")); moddi = new File(unpackedSip, "data/West_mets.xml").lastModified(); modDate = new Date(moddi); tagStr = dateForm.format(modDate); assertTrue(tagStr.equals("23.12.1978")); moddi = new File(unpackedSip, "data/unter1/Pest17.bmp").lastModified(); modDate = new Date(moddi); tagStr = dateForm.format(modDate); assertTrue(tagStr.equals("25.10.2012")); }
From source file:com.astifter.circatext.YahooJSONParser.java
public Weather getWeather(String data, Address address) throws JSONException { Weather weather = new Weather(); // We create out JSONObject from the data JSONObject jObj = new JSONObject(data); JSONObject queryObj = getObject("query", jObj); try {// w w w .j a v a 2 s . com @SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); weather.time = sdf.parse(getString("created", queryObj)); } catch (Throwable t) { weather.time = null; } JSONObject resultsObj = getObject("results", queryObj); JSONObject channelObj = getObject("channel", resultsObj); JSONObject itemObj = getObject("item", channelObj); JSONObject condition = getObject("condition", itemObj); weather.currentCondition.setCondition(getString("text", condition)); int code = getInt("code", condition); weather.currentCondition.setWeatherId(code); weather.currentCondition.setDescr(Weather.translateYahoo(code)); float temperatureF = getFloat("temp", condition); float temperatureC = (temperatureF - 32f) / 1.8f; weather.temperature.setTemp(temperatureC); try { // Tue, 04 Aug 2015 10:59 pm CEST Locale l = Locale.ENGLISH; SimpleDateFormat sdf = new SimpleDateFormat("E, d MMM yyyy hh:mm a", l); String date = getString("date", condition).replace("pm", "PM").replace("am", "AM"); weather.lastupdate = sdf.parse(date); } catch (Throwable t) { weather.lastupdate = null; } Location loc = new Location(); loc.setCountry(address.getCountryCode()); loc.setCity(address.getLocality()); weather.location = loc; return weather; }
From source file:info.archinnov.achilles.it.TestAsyncDSLSimpleEntity.java
@Test public void should_dsl_select_slice_async() throws Exception { //Given/*ww w .j a v a2s . c o m*/ final Map<String, Object> values = new HashMap<>(); final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE); values.put("id", id); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); final Date date1 = dateFormat.parse("2015-10-01 00:00:00 GMT"); final Date date9 = dateFormat.parse("2015-10-09 00:00:00 GMT"); values.put("date1", "'2015-10-01 00:00:00+0000'"); values.put("date2", "'2015-10-02 00:00:00+0000'"); values.put("date3", "'2015-10-03 00:00:00+0000'"); values.put("date4", "'2015-10-04 00:00:00+0000'"); values.put("date5", "'2015-10-05 00:00:00+0000'"); values.put("date6", "'2015-10-06 00:00:00+0000'"); values.put("date7", "'2015-10-07 00:00:00+0000'"); values.put("date8", "'2015-10-08 00:00:00+0000'"); values.put("date9", "'2015-10-09 00:00:00+0000'"); scriptExecutor.executeScriptTemplate("SimpleEntity/insert_many_rows.cql", values); final CountDownLatch latch = new CountDownLatch(1); final CassandraLogAsserter logAsserter = new CassandraLogAsserter(); logAsserter.prepareLogLevel(ASYNC_LOGGER_STRING, "%msg - [%thread]%n"); //When final CompletableFuture<List<SimpleEntity>> future = manager.dsl().select().consistencyList().simpleSet() .simpleMap().value().simpleMap().fromBaseTable().where().id_Eq(id).date_Gte_And_Lt(date1, date9) .withResultSetAsyncListener(rs -> { LOGGER.info(CALLED); latch.countDown(); return rs; }).withTracing().getListAsync(); //Then latch.await(); assertThat(future.get()).hasSize(8); logAsserter.assertContains("Called - [achilles-default-executor"); }
From source file:com.hybris.datahub.core.util.OutboundServiceCsvUtilsUnitTest.java
@Test public void testGetStringValueOfObject_StringValueOfUtcDateCanBeConvertedBackToOriginalDate() throws ParseException { final Date originalDate = new Date(); final String formattedDate = csvUtils.getStringValueOfObject(originalDate); final SimpleDateFormat formatter = new SimpleDateFormat(DEFAULT_DATE_FORMAT); formatter.setTimeZone(TimeZone.getTimeZone("UTC")); final Date convertedDate = formatter.parse(formattedDate); Assert.assertTrue(originalDate.getTime() == convertedDate.getTime()); Assert.assertEquals(0, originalDate.compareTo(convertedDate)); }
From source file:com.persistent.cloudninja.scheduler.TenantDBBandwidthProcessor.java
@Override public boolean execute() { boolean retVal = true; int tenantDBBWsCount = 0; try {/*from w w w .j ava2 s . c om*/ LOGGER.debug("In Processor"); TenantDBBandwidthQueue queue = (TenantDBBandwidthQueue) getWorkQueue(); String message = queue.dequeue(SchedulerSettings.MessageVisibilityTimeout); if (message == null) { retVal = false; LOGGER.debug("Processor : msg is null"); } else { StopWatch watch = new StopWatch(); watch.start(); LOGGER.debug("Processor : msg is " + message); List<DBBandwidthUsageEntity> listDbBandwidthUsageEntities = partitionStatsAndBWUsageDao .getBandwidthUsage(); tenantDBBWsCount = listDbBandwidthUsageEntities.size(); Map<String, MeteringEntity> map = new HashMap<String, MeteringEntity>(); MeteringEntity meteringEntity = null; String dbName = null; String tenantId = null; for (DBBandwidthUsageEntity dbBandwidthUsageEntity : listDbBandwidthUsageEntities) { dbName = dbBandwidthUsageEntity.getDatabaseName(); if (dbName.startsWith("tnt_")) { tenantId = dbName.substring(4); if (map.containsKey(tenantId)) { meteringEntity = map.get(tenantId); setDatabaseBandwidth(dbBandwidthUsageEntity, meteringEntity); } else { meteringEntity = new MeteringEntity(); meteringEntity.setTenantId(tenantId); setDatabaseBandwidth(dbBandwidthUsageEntity, meteringEntity); map.put(tenantId, meteringEntity); } } } Calendar calendar = Calendar.getInstance(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); String date = dateFormat.format(calendar.getTime()); for (Iterator<MeteringEntity> iterator = map.values().iterator(); iterator.hasNext();) { meteringEntity = (MeteringEntity) iterator.next(); meteringEntity.setSnapshotTime(dateFormat.parse(date)); meteringDao.add(meteringEntity); } LOGGER.info("Processor : DB bandwidth calculated."); watch.stop(); taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(), "ProcessMeteringTenantDBBandwidthUse", "Measured the database bandwith use for " + tenantDBBWsCount + " tenants."); } } catch (StorageException e) { retVal = false; LOGGER.error(e.getMessage(), e); } catch (ParseException e) { retVal = false; LOGGER.error(e.getMessage(), e); } return retVal; }
From source file:org.akvo.flow.api.FlowApi.java
@SuppressLint("SimpleDateFormat") private String getTimestamp() { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); try {/*from w w w.j a v a2 s . com*/ return URLEncoder.encode(dateFormat.format(new Date()), "UTF-8"); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.getMessage()); return null; } }
From source file:edu.jhu.pha.vospace.jobs.JobsProcessor.java
/** * Adds the new job to the SQL database/*from w ww . j ava 2 s .com*/ * @param job The job description object */ public void submitJob(final String login, final JobDescription job) { final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); final byte[] jobSer; try { jobSer = (new ObjectMapper()).writeValueAsBytes(job); } catch (Exception ex) { ex.printStackTrace(); throw new InternalServerErrorException(ex.getMessage()); } DbPoolServlet.goSql("Submit job", "insert into jobs (id,user_id,starttime,state,direction,target,json_notation) select ?, user_id, ?,?,?,?,? from user_identities WHERE identity = ?", new SqlWorker<Integer>() { @Override public Integer go(Connection conn, PreparedStatement stmt) throws SQLException { stmt.setString(1, job.getId()); stmt.setString(2, dateFormat.format(job.getStartTime().getTime())); stmt.setString(3, job.getState().toString()); stmt.setString(4, job.getDirection().toString()); stmt.setString(5, job.getTarget().toString()); stmt.setBytes(6, jobSer); stmt.setString(7, login); return stmt.executeUpdate(); } }); }
From source file:com.android.projecte.townportal.WeatherInfo.java
public String convertDate(long unixTime) { SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.US); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(unixTime * 1000); sdf.setTimeZone(cal.getTimeZone()); return sdf.format(cal.getTime()); }