Languages
[Edit]
EN

Java - create ZonedDateTime from string (yyyy-MM-dd HH:mm:ss)

6 points
Created by:
Tomeriko
413

Solution:

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

public class Example {

    public static void main(String[] args) {
        String dateText = "2021-05-13 11:59:00";

        ZonedDateTime zonedDateTime = LocalDateTime.parse(
                dateText,
                DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
        ).atZone(ZoneId.of("UTC"));

        System.out.println(zonedDateTime); // 2021-05-13T11:59Z[UTC]
    }
}

 

Alternative titles

  1. Create ZonedDateTime from string in java
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join