List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:org.silverpeas.core.calendar.CalendarEventStubBuilder.java
public CalendarEventStubBuilder withCreationDate(final OffsetDateTime createDate) { component.withCreateDate(Date.from(createDate.toInstant())); return this; }
From source file:cn.afterturn.easypoi.excel.export.base.ExportCommonService.java
private Object dateFormatValue(Object value, ExcelExportEntity entity) throws Exception { Date temp = null;/*w w w. java 2s . co m*/ if (value instanceof String && StringUtils.isNoneEmpty(value.toString())) { SimpleDateFormat format = new SimpleDateFormat(entity.getDatabaseFormat()); temp = format.parse(value.toString()); } else if (value instanceof Date) { temp = (Date) value; } else if (value instanceof Instant) { Instant instant = (Instant) value; temp = Date.from(instant); } else if (value instanceof LocalDate) { LocalDate localDate = (LocalDate) value; temp = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); } else if (value instanceof LocalDateTime) { LocalDateTime localDateTime = (LocalDateTime) value; temp = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); } else if (value instanceof java.sql.Date) { temp = new Date(((java.sql.Date) value).getTime()); } else if (value instanceof java.sql.Time) { temp = new Date(((java.sql.Time) value).getTime()); } else if (value instanceof java.sql.Timestamp) { temp = new Date(((java.sql.Timestamp) value).getTime()); } if (temp != null) { SimpleDateFormat format = new SimpleDateFormat(entity.getFormat()); if (StringUtils.isNotEmpty(entity.getTimezone())) { format.setTimeZone(TimeZone.getTimeZone(entity.getTimezone())); } value = format.format(temp); } return value; }
From source file:com.example.geomesa.kafka.KafkaQuickStart.java
public static void addSimpleFeatures(SimpleFeatureType sft, FeatureStore producerFS, String visibility) throws InterruptedException, IOException { final int MIN_X = -180; final int MAX_X = 180; final int MIN_Y = -90; final int MAX_Y = 90; final int DX = 2; final int DY = 1; final String[] PEOPLE_NAMES = { "James", "John", "Peter", "Hannah", "Claire", "Gabriel" }; final long SECONDS_PER_YEAR = 365L * 24L * 60L * 60L; final Random random = new Random(); final ZonedDateTime MIN_DATE = ZonedDateTime.of(2015, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(sft); DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(); // creates and updates two SimpleFeatures. // the first time this for loop runs the two SimpleFeatures are created. // in the subsequent iterations of the for loop, the two SimpleFeatures are updated. int numFeatures = (MAX_X - MIN_X) / DX; for (int i = 1; i <= numFeatures; i++) { builder.add(PEOPLE_NAMES[i % PEOPLE_NAMES.length]); // name builder.add((int) Math.round(random.nextDouble() * 110)); // age builder.add(Date.from( MIN_DATE.plusSeconds((int) Math.round(random.nextDouble() * SECONDS_PER_YEAR)).toInstant())); // dtg builder.add(WKTUtils$.MODULE$.read("POINT(" + (MIN_X + DX * i) + " " + (MIN_Y + DY * i) + ")")); // geom SimpleFeature feature1 = builder.buildFeature("1"); feature1.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE); builder.add(PEOPLE_NAMES[(i + 1) % PEOPLE_NAMES.length]); // name builder.add((int) Math.round(random.nextDouble() * 110)); // age builder.add(Date.from(/*from w w w .j a va 2s . co m*/ MIN_DATE.plusSeconds((int) Math.round(random.nextDouble() * SECONDS_PER_YEAR)).toInstant())); // dtg builder.add(WKTUtils$.MODULE$.read("POINT(" + (MIN_X + DX * i) + " " + (MAX_Y - DY * i) + ")")); // geom SimpleFeature feature2 = builder.buildFeature("2"); feature2.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE); if (visibility != null) { feature1.getUserData().put("geomesa.feature.visibility", visibility); feature2.getUserData().put("geomesa.feature.visibility", visibility); } // write the SimpleFeatures to Kafka featureCollection.add(feature1); featureCollection.add(feature2); producerFS.addFeatures(featureCollection); featureCollection.clear(); // wait 100 ms in between updating SimpleFeatures to simulate a stream of data Thread.sleep(100); } }
From source file:org.silverpeas.core.calendar.CalendarEventStubBuilder.java
public CalendarEventStubBuilder withLastUpdateDate(final OffsetDateTime lastUpdateDate) { component.withLastUpdateDate(Date.from(lastUpdateDate.toInstant())); return this; }
From source file:com.vmware.photon.controller.api.client.resource.ClusterApiTest.java
@Test public void testDeleteAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); ClusterApi clusterApi = new ClusterApi(restClient); final CountDownLatch latch = new CountDownLatch(1); clusterApi.deleteAsync("foo", new FutureCallback<Task>() { @Override// w w w .j a v a 2s .c o m public void onSuccess(Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.ClusterRestApiTest.java
@Test public void testDeleteAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); ClusterApi clusterApi = new ClusterRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); clusterApi.deleteAsync("foo", new FutureCallback<Task>() { @Override/*from w w w. j av a2s . c om*/ public void onSuccess(Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:me.rkfg.xmpp.bot.plugins.FaggotOfTheDayPlugin.java
private Date getFirstTime() { final LocalTime midnight = LocalTime.MIDNIGHT; final LocalDate today = LocalDate.now(); final LocalDateTime todayMidnight = LocalDateTime.of(today, midnight); return Date.from(todayMidnight.atZone(ZoneId.systemDefault()).toInstant()); }
From source file:net.ljcomputing.ecsr.security.service.impl.JwtTokenServiceImpl.java
/** * Calculate the new expiration date from now. * * @return the date/*from w w w. j a v a 2s .c om*/ */ private Date expirationDate() { final LocalDateTime expirationLdt = ldtNow.plusMinutes(tokenExpirationTime); // NOPMD final ZonedDateTime zdt = expirationLdt.atZone(ZONE_ID); // NOPMD final Instant instant = zdt.toInstant(); // NOPMD return Date.from(instant); // NOPMD }
From source file:net.bis5.slack.command.gcal.SlashCommandApi.java
private Date toDate(LocalDateTime dateTime) { return Date.from(dateTime.toInstant(ZoneOffset.ofHours(+9))); }
From source file:org.ng200.openolympus.controller.contest.ContestViewController.java
@PreAuthorize(SecurityExpressionConstants.IS_ADMIN + SecurityExpressionConstants.OR + '(' + SecurityExpressionConstants.IS_USER + SecurityExpressionConstants.AND + SecurityExpressionConstants.THIS_CONTEST_IN_PROGRESS_FOR_USER + ')') @Cacheable(value = "contests", key = "#contest.id", unless = "#result == null") @RequestMapping(value = "/api/contest/{contest}", method = RequestMethod.GET) @JsonView(UnprivilegedView.class) public ContestDTO showContestHub(@PathVariable(value = "contest") final Contest contest, final Principal principal) { User user = userService.getUserByUsername(principal.getName()); Set<Task> tasks = new HashSet<Task>(contest.getTasks()); return new ContestDTO(contest.getName(), new TimingDTO(contest.getStartTime(), Date.from(contest.getStartTime().toInstant().plus(contest.getDuration())), contestService.getContestEndTimeForUser(contest, user)), tasks);/*from w w w. j ava 2s . c om*/ }