Java ZonedDateTime to Date
https://stackoverflow.com/a/32274725
You can convert ZonedDateTime to an instant, which you can use directly with Date.
Date.from(java.time.ZonedDateTime.now().toInstant());
UTC Date and Time in Various Formats
Date Time Format | UTC Date Time Now |
---|---|
UTC | 2022-04-05T08:28:33Z |
ISO-8601 | 2022-04-05T08:28:33+0000 |
RFC 2822 | Tue, 05 Apr 2022 08:28:33 +0000 |
RFC 850 | Tuesday, 05-Apr-22 08:28:33 UTC |
RFC 1036 | Tue, 05 Apr 22 08:28:33 +0000 |
RFC 1123 | Tue, 05 Apr 2022 08:28:33 +0000 |
RFC 822 | Tue, 05 Apr 22 08:28:33 +0000 |
RFC 3339 | 2022-04-05T08:28:33+00:00 |
ATOM | 2022-04-05T08:28:33+00:00 |
COOKIE | Tuesday, 05-Apr-2022 08:28:33 UTC |
RSS | Tue, 05 Apr 2022 08:28:33 +0000 |
W3C | 2022-04-05T08:28:33+00:00 |
Unix Epoch | 1649147313 |
YYYY-DD-MM HH:MM:SS | 2022-05-04 08:28:33 |
YYYY-DD-MM HH:MM:SS am/pm | 2022-05-04 08:28:33 AM |
DD-MM-YYYY HH:MM:SS | 05-04-2022 08:28:33 |
MM-DD-YYYY HH:MM:SS | 04-05-2022 08:28:33 |
Unable to obtain LocalDateTime from TemporalAccessor when parsing LocalDateTime (Java 8)
If you really need to transform a date to a LocalDateTime object, you could use the LocalDate.atStartOfDay(). This will give you a LocalDateTime object at the specified date, having the hour, minute and second fields set to 0:
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDateTime time = LocalDate.parse("20140218", formatter).atStartOfDay();
No comments:
Post a Comment