How to print a date using DateTimeFormatter.ISO_LOCAL_DATE?

yegor256

I want to use DateTimeFormatter.ISO_LOCAL_DATE to print and parse dates. This is what I'm doing for printing:

Date date;
String text = DateTimeFormatter.ISO_LOCAL_DATE.format(
  date.toInstant()
);

This is what I'm getting:

java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: Year
  at java.time.Instant.getLong(Instant.java:603)
  at java.time.format.DateTimePrintContext$1.getLong(DateTimePrintContext.java:205)
  at java.time.format.DateTimePrintContext.getValue(DateTimePrintContext.java:298)
  at java.time.format.DateTimeFormatterBuilder$NumberPrinterParser.format(DateTimeFormatterBuilder.java:2543)
  at java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(DateTimeFormatterBuilder.java:2182)
  at java.time.format.DateTimeFormatter.formatTo(DateTimeFormatter.java:1744)
  at java.time.format.DateTimeFormatter.format(DateTimeFormatter.java:1718)
yegor256

This is how it works:

String text = DateTimeFormatter.ISO_LOCAL_DATE
  .withZone(ZoneId.of("UTC"))
  .format(date.toInstant());

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

ThreeTenABP: How to validate date using a custom date format / DateTimeFormatter?

From Dev

Parsing a date using DateTimeFormatter ofPattern

From Dev

Parsing date without month using DateTimeFormatter

From Java

Date Format Issue With DateTimeFormatter

From Dev

How to display / print current date and next date using javascript

From Dev

Runtime exception while trying to parse date time using joda DateTimeFormatter

From Dev

Using new Java 8 DateTimeFormatter to do strict date parsing

From Dev

How to print the current time and date in ISO date format in java?

From Dev

How to get the date-time pattern from a DateTimeFormatter object

From Dev

How to aggregate data by date and string multiIndex using Pandas, then print to .csv?

From Dev

How can I print a stored date using locales?

From Dev

How to print Current Time and Date

From Java

How to print a date in a regular format?

From Dev

How to print date and time with jquery

From Dev

How to print Current Time and Date

From Dev

How to print a given date in C

From Dev

What is the equivalent format string of DateTimeFormatter.ISO_OFFSET_DATE_TIME?

From Java

DateTimeFormatter adding a year to date after formatting

From Java

DateTimeFormatter cannot be applied to (java.util.Date)

From Dev

parsing date from day of week with java datetimeformatter

From Dev

Print incremental date using while loop in bash

From Dev

Print date from yaml to ruby using middleman

From Dev

print last date of previous month using date command

From Dev

How to change the base date for parsing two letter years with Java 8 DateTimeFormatter?

From Dev

Bash, how to print date with a different locale

From Dev

How to print the date and time in Python from string?

From Dev

how can you print the time and date in python

From Dev

How to print formatted date in F#

From Dev

How to print line by date range update

Related Related

  1. 1

    ThreeTenABP: How to validate date using a custom date format / DateTimeFormatter?

  2. 2

    Parsing a date using DateTimeFormatter ofPattern

  3. 3

    Parsing date without month using DateTimeFormatter

  4. 4

    Date Format Issue With DateTimeFormatter

  5. 5

    How to display / print current date and next date using javascript

  6. 6

    Runtime exception while trying to parse date time using joda DateTimeFormatter

  7. 7

    Using new Java 8 DateTimeFormatter to do strict date parsing

  8. 8

    How to print the current time and date in ISO date format in java?

  9. 9

    How to get the date-time pattern from a DateTimeFormatter object

  10. 10

    How to aggregate data by date and string multiIndex using Pandas, then print to .csv?

  11. 11

    How can I print a stored date using locales?

  12. 12

    How to print Current Time and Date

  13. 13

    How to print a date in a regular format?

  14. 14

    How to print date and time with jquery

  15. 15

    How to print Current Time and Date

  16. 16

    How to print a given date in C

  17. 17

    What is the equivalent format string of DateTimeFormatter.ISO_OFFSET_DATE_TIME?

  18. 18

    DateTimeFormatter adding a year to date after formatting

  19. 19

    DateTimeFormatter cannot be applied to (java.util.Date)

  20. 20

    parsing date from day of week with java datetimeformatter

  21. 21

    Print incremental date using while loop in bash

  22. 22

    Print date from yaml to ruby using middleman

  23. 23

    print last date of previous month using date command

  24. 24

    How to change the base date for parsing two letter years with Java 8 DateTimeFormatter?

  25. 25

    Bash, how to print date with a different locale

  26. 26

    How to print the date and time in Python from string?

  27. 27

    how can you print the time and date in python

  28. 28

    How to print formatted date in F#

  29. 29

    How to print line by date range update

HotTag

Archive