List of usage examples for java.time ZonedDateTime getHour
public int getHour()
From source file:Main.java
public static void main(String[] args) { ZonedDateTime dateTime = ZonedDateTime.now(); System.out.println(dateTime.getHour()); }
From source file:Main.java
public static void main(String[] argv) { ZonedDateTime paris = ZonedDateTime.now(ZoneId.of("Europe/Paris")); ZonedDateTime london = ZonedDateTime.now(ZoneId.of("Europe/London")); System.out.println(paris.getHour() - london.getHour()); }
From source file:onl.area51.httpd.action.Request.java
default Request addHeader(String n, ZonedDateTime zdt) { return addHeader(n, String.format("%3s, %02d %3s %d %02d:%02d:%02d GMT", zdt.getDayOfWeek().getDisplayName(TextStyle.SHORT, Locale.ENGLISH), zdt.getDayOfMonth(), zdt.getMonth().getDisplayName(TextStyle.SHORT, Locale.ENGLISH), zdt.getYear(), zdt.getHour(), zdt.getMinute(), zdt.getSecond())); }
From source file:org.caratarse.auth.model.dao.UserAttributesTest.java
@Test public void lastUserAttribute() { User user = retrieveUserWithAttributes(); Attribute attribute = user.getUserAttributes().get("last"); assertTrue(attribute instanceof DateTimeAttribute); assertThat(attribute.getName(), is("last")); final Date value = new Date(((Date) attribute.getValue()).getTime()); ZonedDateTime v = value.toInstant().atZone(ZoneId.of("UTC")); assertThat(v.getDayOfMonth(), is(20)); assertThat(v.getMonthValue(), is(11)); assertThat(v.getYear(), is(2015));/* w w w . j a v a 2 s . com*/ assertThat(v.getHour(), is(12)); assertThat(v.getMinute(), is(11)); assertThat(v.getSecond(), is(10)); assertThat(v.getNano(), is(999000000)); }
From source file:org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest.java
/** * Gets a valid cron expression describing a schedule with a single * maintenance window, starting specified number of minutes after current * time./*from w w w . j av a 2s . com*/ * * @param minutesToAdd * is the number of minutes after the current time * * @return {@link String} containing a valid cron expression. */ protected static String getTestSchedule(final int minutesToAdd) { ZonedDateTime currentTime = ZonedDateTime.now(); currentTime = currentTime.plusMinutes(minutesToAdd); return String.format("%d %d %d %d %d ? %d", currentTime.getSecond(), currentTime.getMinute(), currentTime.getHour(), currentTime.getDayOfMonth(), currentTime.getMonthValue(), currentTime.getYear()); }
From source file:org.primeframework.mvc.parameter.convert.converters.ZonedDateTimeConverterTest.java
@Test public void fromStrings() { GlobalConverter converter = new ZonedDateTimeConverter(new MockConfiguration()); ZonedDateTime value = (ZonedDateTime) converter.convertFromStrings(ZonedDateTime.class, null, "testExpr", ArrayUtils.toArray((String) null)); assertNull(value);/*ww w. ja v a 2s . co m*/ value = (ZonedDateTime) converter.convertFromStrings(Locale.class, MapBuilder.asMap("dateTimeFormat", "MM-dd-yyyy hh:mm:ss a Z"), "testExpr", ArrayUtils.toArray("07-08-2008 10:13:34 AM -0800")); assertEquals(value.getMonthValue(), 7); assertEquals(value.getDayOfMonth(), 8); assertEquals(value.getYear(), 2008); assertEquals(value.getHour(), 10); assertEquals(value.getMinute(), 13); assertEquals(value.getSecond(), 34); assertEquals(value.getZone(), ZoneOffset.ofHours(-8)); try { converter.convertFromStrings(Locale.class, MapBuilder.asMap("dateTimeFormat", "MM-dd-yyyy"), "testExpr", ArrayUtils.toArray("07/08/2008")); fail("Should have failed"); } catch (ConversionException e) { // Expected } }
From source file:org.tightblog.ui.restapi.WeblogEntryController.java
@GetMapping(value = "/{id}") public WeblogEntry getWeblogEntry(@PathVariable String id, Principal p, HttpServletResponse response) throws ServletException { try {//from w ww. j a va 2 s . c o m WeblogEntry entry = weblogEntryRepository.findByIdOrNull(id); if (entry != null) { Weblog weblog = entry.getWeblog(); if (userManager.checkWeblogRole(p.getName(), weblog, WeblogRole.EDIT_DRAFT)) { entry.setCommentsUrl(urlService.getCommentManagementURL(weblog.getId(), entry.getId())); entry.setPermalink(urlService.getWeblogEntryURL(entry)); entry.setPreviewUrl(urlService.getWeblogEntryDraftPreviewURL(entry)); if (entry.getPubTime() != null) { log.debug("entry pubtime is {}", entry.getPubTime()); ZonedDateTime zdt = entry.getPubTime().atZone(entry.getWeblog().getZoneId()); entry.setHours(zdt.getHour()); entry.setMinutes(zdt.getMinute()); entry.setCreator(null); entry.setDateString(pubDateFormat.format(zdt.toLocalDate())); } response.setStatus(HttpServletResponse.SC_OK); return entry; } else { response.setStatus(HttpServletResponse.SC_FORBIDDEN); } } else { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } } catch (Exception e) { log.error("Error retrieving entry {}", id, e); throw new ServletException(e.getMessage()); } return null; }
From source file:stroom.pipeline.server.writer.PathCreator.java
public static String replaceTimeVars(String path) { // Replace some of the path elements with system variables. final ZonedDateTime dateTime = ZonedDateTime.now(ZoneOffset.UTC); path = replace(path, "year", dateTime.getYear(), 4); path = replace(path, "month", dateTime.getMonthValue(), 2); path = replace(path, "day", dateTime.getDayOfMonth(), 2); path = replace(path, "hour", dateTime.getHour(), 2); path = replace(path, "minute", dateTime.getMinute(), 2); path = replace(path, "second", dateTime.getSecond(), 2); path = replace(path, "millis", dateTime.toInstant().toEpochMilli(), 3); path = replace(path, "ms", dateTime.toInstant().toEpochMilli(), 0); return path;/* www . j a va2 s. co m*/ }