List of usage examples for java.time OffsetDateTime format
public String format(DateTimeFormatter formatter)
From source file:Main.java
public static void main(String[] args) { OffsetDateTime o = OffsetDateTime.now(); String l = o.format(DateTimeFormatter.ISO_DATE_TIME); System.out.println(l);/*from w w w . j ava 2s . c om*/ }
From source file:Main.java
public static void main(String[] argv) { LocalDate ld = LocalDate.now(); String ldStr = ld.format(DateTimeFormatter.ISO_DATE); System.out.println("Local Date: " + ldStr); OffsetDateTime odt = OffsetDateTime.now(); String odtStr = odt.format(DateTimeFormatter.ISO_DATE); System.out.println("Offset Datetime: " + odtStr); ZonedDateTime zdt = ZonedDateTime.now(); String zdtStr = zdt.format(DateTimeFormatter.ISO_DATE); System.out.println("Zoned Datetime: " + zdtStr); }
From source file:com.intuit.wasabi.api.pagination.filters.FilterUtil.java
/** * Formats a date as it is shown in the UI to allow for matching searches on date fields. * Needs the requesting user's timezone offset to UTC for correct matches. * * @param date the date/*ww w . j av a2s. com*/ * @param timeZoneOffset the timezone offset to UTC * @return a timezone offset adjusted string of the UI pattern {@code MMM d, YYYY HH:mm:ss a}. */ /*test*/ static String formatDateTimeAsUI(OffsetDateTime date, String timeZoneOffset) { try { return date.format(DateTimeFormatter.ofPattern("MMM d, YYYY HH:mm:ss a") .withZone(ZoneId.ofOffset("UTC", ZoneOffset.of(timeZoneOffset)))); } catch (DateTimeException dateTimeException) { throw new PaginationException(ErrorCode.FILTER_KEY_UNPROCESSABLE, "Wrong format: Can not parse timezone '" + timeZoneOffset + "' or date " + date.toString() + " properly.", dateTimeException); } }
From source file:org.springframework.session.web.http.DefaultCookieSerializer.java
@Override public void writeCookieValue(CookieValue cookieValue) { HttpServletRequest request = cookieValue.getRequest(); HttpServletResponse response = cookieValue.getResponse(); StringBuilder sb = new StringBuilder(); sb.append(this.cookieName).append('='); String value = getValue(cookieValue); if (value != null && value.length() > 0) { validateValue(value);/*from w w w .j ava 2 s . com*/ sb.append(value); } int maxAge = getMaxAge(cookieValue); if (maxAge > -1) { sb.append("; Max-Age=").append(cookieValue.getCookieMaxAge()); OffsetDateTime expires = (maxAge != 0) ? OffsetDateTime.now().plusSeconds(maxAge) : Instant.EPOCH.atOffset(ZoneOffset.UTC); sb.append("; Expires=").append(expires.format(DateTimeFormatter.RFC_1123_DATE_TIME)); } String domain = getDomainName(request); if (domain != null && domain.length() > 0) { validateDomain(domain); sb.append("; Domain=").append(domain); } String path = getCookiePath(request); if (path != null && path.length() > 0) { validatePath(path); sb.append("; Path=").append(path); } if (isSecureCookie(request)) { sb.append("; Secure"); } if (this.useHttpOnlyCookie) { sb.append("; HttpOnly"); } if (this.sameSite != null) { sb.append("; SameSite=").append(this.sameSite); } response.addHeader("Set-Cookie", sb.toString()); }