Languages
[Edit]
EN

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

6 points
Created by:
Tomeriko
263

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]
    }
}

 

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