Example usage for java.time ZonedDateTime now

List of usage examples for java.time ZonedDateTime now

Introduction

In this page you can find the example usage for java.time ZonedDateTime now.

Prototype

public static ZonedDateTime now() 

Source Link

Document

Obtains the current date-time from the system clock in the default time-zone.

Usage

From source file:Main.java

public static void main(String[] argv) {
    String ldStr = DateTimeFormatter.ISO_DATE.format(LocalDate.now());
    System.out.println(ldStr);//from   ww w.  jav a 2 s  . c  o m
    String odtStr = DateTimeFormatter.ISO_DATE.format(OffsetDateTime.now());
    System.out.println(odtStr);
    String zdtStr = DateTimeFormatter.ISO_DATE.format(ZonedDateTime.now());
    System.out.println(zdtStr);
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate localDate = LocalDate.now();
    System.out.println(localDate);

    LocalTime localTime = LocalTime.now();
    System.out.println(localTime);

    LocalDateTime dateTime = LocalDateTime.now();
    System.out.println(dateTime);

    ZonedDateTime dateTimeWithZone = ZonedDateTime.now();
    System.out.println(dateTimeWithZone);
}

From source file:Main.java

public static void main(String[] argv) {

    Date dateFromInstant = Date.from(Instant.now());
    System.out.println(dateFromInstant);
    java.util.TimeZone timeZone = java.util.TimeZone.getTimeZone(ZoneId.of("America/Los_Angeles"));
    System.out.println(timeZone);

    GregorianCalendar gregorianCalendar = GregorianCalendar.from(ZonedDateTime.now());
}

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:Main.java

public static void main(String[] argv) {

    LocalDateTime now = LocalDateTime.now();
    ZonedDateTime zonedDateTime = ZonedDateTime.of(now, TimeZone.NEW_YORK);
    System.out.println("now = " + now);
    System.out.println("Current date and time in a particular timezone : " + zonedDateTime);

    now = LocalDateTime.now(TimeZone.INDIA);
    System.out.println("now in India = " + now);

    zonedDateTime = ZonedDateTime.now();
    System.out.println("zonedDateTime with default(system) timezone = " + zonedDateTime);
    System.out.println("zonedDateTime with India timezone = " + ZonedDateTime.now(TimeZone.INDIA));

    String isoFormatted = DateTimeFormatter.ISO_INSTANT.format(ZonedDateTime.now(TimeZone.INDIA));
    System.out.println("ISO Formatted = " + isoFormatted);

    ZonedDateTime utahMarch8thAt2AM = ZonedDateTime.of(LocalDateTime.of(2015, 3, 8, 1, 0), TimeZone.UTAH);
    System.out.println("utahMarch8thAt2AM = " + utahMarch8thAt2AM);
    System.out.println("utahMarch8thAt2AM.plusHours(1) = " + utahMarch8thAt2AM.plusHours(1));
    System.out.println("utahMarch8thAt2AM.plusHours(2) = " + utahMarch8thAt2AM.plusHours(2));
}

From source file:com.mgmtp.perfload.core.console.meta.LtMetaInfoHandlerTest.java

@Test
public void testMetaInfoForLoadProfileTest() throws Exception {
    XmlConfigReader reader = new XmlConfigReader(new File("src/test/resources"), "testplan_loadprofile.xml");
    ZonedDateTime now = ZonedDateTime.now();
    Properties props = createMetaProperties(reader, now);
    String timestamp = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(now);

    assertEquals(props.getProperty("test.file"), "testplan_loadprofile.xml");
    assertEquals(props.getProperty("test.start"), timestamp);
    assertEquals(props.getProperty("test.finish"), timestamp);
    assertEquals(props.getProperty("daemon.1"), "localhost:8042");
    assertEquals(props.getProperty("daemon.2"), "localhost:8043");
    assertEquals(props.getProperty("targets"), "myTarget1,myTarget2");
    assertEquals(props.getProperty("operations"),
            "myOperation1,myOperation2,myOperation3,myOperation4,myOperation5,myOperation6");
    assertEquals(props.getProperty("executions.myOperation1.myTarget1"), "1");
    assertEquals(props.getProperty("executions.myOperation1.myTarget2"), "1");
    assertEquals(props.getProperty("executions.myOperation2.myTarget1"), "2");
    assertEquals(props.getProperty("executions.myOperation2.myTarget2"), "2");
    assertEquals(props.getProperty("executions.myOperation3.myTarget1"), "1");
    assertEquals(props.getProperty("executions.myOperation3.myTarget2"), "0");
    assertEquals(props.getProperty("executions.myOperation4.myTarget1"), "3");
    assertEquals(props.getProperty("executions.myOperation4.myTarget2"), "0");
    assertEquals(props.getProperty("executions.myOperation5.myTarget1"), "0");
    assertEquals(props.getProperty("executions.myOperation5.myTarget2"), "1");
    assertEquals(props.getProperty("executions.myOperation6.myTarget1"), "0");
    assertEquals(props.getProperty("executions.myOperation6.myTarget2"), "4");
}

From source file:org.craftercms.deployer.impl.TargetContextImpl.java

public TargetContextImpl(String id, DeploymentPipeline deploymentPipeline,
        ConfigurableApplicationContext applicationContext) {
    this.id = id;
    this.deploymentPipeline = deploymentPipeline;
    this.applicationContext = applicationContext;
    this.dateCreated = ZonedDateTime.now();
}

From source file:org.mascherl.example.service.SendMailService.java

@Transactional
public void sendMail(Mail mail, User currentUser) {
    if (!Objects.equals(currentUser.getEmail(), mail.getFrom().getAddress())) {
        throw new IllegalArgumentException("User can only send an email from his own address");
    }/*from ww  w  . jav a 2 s  . c  om*/
    if (mail.getTo() == null || mail.getTo().isEmpty()) {
        throw new IllegalArgumentException("Receiver list cannot be empty");
    }

    ZonedDateTime sendTime = ZonedDateTime.now();

    MailEntity sendEntity;
    if (mail.getUuid() != null) {
        sendEntity = em.find(MailEntity.class, mail.getUuid());
        if (!Objects.equals(sendEntity.getUser().getUuid(), currentUser.getUuid())) {
            throw new IllegalArgumentException("The mail to be sent is not a draft of the current user.");
        }
        if (sendEntity.getMailType() != MailType.DRAFT) {
            throw new IllegalArgumentException(
                    "The mail to be sent needs to be a draft, but it is of type " + sendEntity.getMailType());
        }
        sendEntity.setMailType(MailType.SENT);
    } else {
        sendEntity = new MailEntity(MailType.SENT);
        sendEntity.setUser(em.getReference(UserEntity.class, currentUser.getUuid()));
    }
    sendEntity.setDateTime(sendTime);
    sendEntity.setUnread(false);
    sendEntity.setFrom(mail.getFrom());
    sendEntity.setTo(mail.getTo());
    sendEntity.setCc(mail.getCc());
    sendEntity.setBcc(mail.getBcc());
    sendEntity.setSubject(mail.getSubject());
    sendEntity.setMessageText(mail.getMessageText());
    em.persist(sendEntity);

    List<String> receiveUserUuids = findReceiveUserUuids(mail);
    for (String receiveUserUuid : receiveUserUuids) {
        MailEntity receiveEntity = new MailEntity(MailType.RECEIVED);
        receiveEntity.setUser(em.getReference(UserEntity.class, receiveUserUuid));
        receiveEntity.setDateTime(sendTime);
        receiveEntity.setUnread(true);
        receiveEntity.setFrom(mail.getFrom());
        receiveEntity.setTo(mail.getTo());
        receiveEntity.setCc(mail.getCc());
        receiveEntity.setBcc(mail.getBcc());
        receiveEntity.setSubject(mail.getSubject());
        receiveEntity.setMessageText(mail.getMessageText());
        em.persist(receiveEntity);
    }

    em.flush();
}

From source file:keywhiz.auth.cookie.CookieAuthenticator.java

private Optional<UserCookieData> getUserCookieData(Cookie sessionCookie) {
    byte[] ciphertext = Base64.getDecoder().decode(sessionCookie.getValue());
    UserCookieData cookieData = null;//from  ww w .  j av a  2 s .c om

    try {
        cookieData = mapper.readValue(encryptor.decrypt(ciphertext), UserCookieData.class);
        if (cookieData.getExpiration().isBefore(ZonedDateTime.now())) {
            cookieData = null;
        }
    } catch (AEADBadTagException e) {
        logger.warn("Cookie with bad MAC detected");
    } catch (Exception e) {
        /* this cookie ain't gettin decrypted, it's bad */ }

    return Optional.ofNullable(cookieData);
}

From source file:de.scanplus.notesphonenumbers.data.AddressData.java

@JsonCreator
public AddressData(@JsonProperty("PhoneNumber") List<String> phoneNumber,
        @JsonProperty("MobileNumber") List<String> mobileNumber,
        @JsonProperty("PrivatPhoneNumber") List<String> privatePhoneNumber,
        @JsonProperty("PrivatMobileNumber") List<String> privateMobileNumber) {
    // normalize numbers to E164 format
    this.spPhoneNumber = normalizeNumber(phoneNumber);
    this.spMobileNumber = normalizeNumber(mobileNumber);
    this.spPrivatePhoneNumber = normalizeNumber(privatePhoneNumber);
    this.spPrivateMobileNumber = normalizeNumber(privateMobileNumber);
    this.spLastPhoneUpdate = ZonedDateTime.now();
}