Beispiel #1
0
  public static void main(String[] args) {
    ZonedDateTime apollo11launch =
        ZonedDateTime.of(1969, 7, 16, 9, 32, 0, 0, ZoneId.of("America/New_York"));

    String formatted = DateTimeFormatter.ISO_DATE_TIME.format(apollo11launch);
    // 1969-07-16T09:32:00-05:00[America/New_York]
    System.out.println(formatted);

    DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG);
    formatted = formatter.format(apollo11launch);
    // July 16, 1969 9:32:00 AM EDT
    System.out.println(formatted);
    formatted = formatter.withLocale(Locale.FRENCH).format(apollo11launch);
    // 16 juillet 1969 09:32:00 EDT
    System.out.println(formatted);

    formatter = DateTimeFormatter.ofPattern("E yyyy-MM-dd HH:mm");
    formatted = formatter.format(apollo11launch);
    System.out.println(formatted);

    LocalDate churchsBirthday = LocalDate.parse("1903-06-14");
    System.out.println("churchsBirthday: " + churchsBirthday);
    apollo11launch =
        ZonedDateTime.parse(
            "1969-07-16 03:32:00-0400", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssxx"));
    System.out.println("apollo11launch: " + apollo11launch);
  }
Beispiel #2
0
  @Test
  public void testLocalDateTime() {
    System.out.println(LocalDateTime.now());
    System.out.println(LocalDateTime.of(1994, Month.MAY, 15, 11, 30));
    System.out.println(LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()));
    System.out.println(LocalDateTime.ofEpochSecond(1450749600, 0, ZoneOffset.ofHours(8)));

    System.out.printf("6 months from now: %s%n", LocalDateTime.now().plusMonths(6));
    System.out.printf("6 days ago: %s%n", LocalDateTime.now().minusDays(6));

    System.out.println(DateTimeFormatter.ISO_DATE_TIME.format(LocalDateTime.now()));
    System.out.println(DateTimeFormatter.ofPattern("MM-dd HH:mm").format(LocalDateTime.now()));
  }
  @Test
  public void testSecretCorrectlySigns() {

    LocalDateTime dateTime =
        LocalDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse("2014-06-03T17:48:47.774453"));

    CoinkiteSigningRequestInterceptor coinkiteSigningRequestInterceptor =
        new CoinkiteSigningRequestInterceptor();
    coinkiteSigningRequestInterceptor.setDateTime(dateTime);

    RequestTemplate template = new RequestTemplate().method("GET").append("/example/endpoint");

    coinkiteSigningRequestInterceptor.apply(template);

    Collection<String> collection = template.headers().get(Constants.X_CK_TIMESTAMP);
    assertEquals(collection.iterator().next(), "2014-06-03T17:48:47.774453");
    collection = template.headers().get(Constants.X_CK_SIGN);
    assertEquals(
        "042341c271b14aaad1c898d35c9ca0bc8552e1cb4d6683f28edd57e3e86ed76c",
        collection.iterator().next());
  }
 public String getCreationTimestamp() {
   if (creationTimestamp == null) {
     creationTimestamp = DateTimeFormatter.ISO_DATE_TIME.format(createdOn.toLocalDateTime());
   }
   return creationTimestamp;
 }