Converting between Strings, Numbers, and Dates in Java
Type a value in the input, then click a conversion method to see the result.
intdoublefloatClick each card to try the problematic input and see what happens.
nextLine() always returns a String. If you need a number, you must parse it!Java uses LocalDate.parse() with a DateTimeFormatter to convert strings into dates.
| Symbol | Meaning | Example (July 5, 2025) |
|---|---|---|
| d | Day (no padding) | 5 |
| dd | Day (zero-padded) | 05 |
| M | Month (no padding) | 7 |
| MM | Month (zero-padded) | 07 |
| MMM | Month abbreviation | Jul |
| MMMM | Full month name | July |
| yy | Two-digit year | 25 |
| yyyy | Four-digit year | 2025 |
yyyy-MM-dd) is the default for LocalDate.parse(). For any other format, you must provide a DateTimeFormatter.
Click each card to see how it works.
nextLine() always returns a String. If you need a number, you must parse it!
+ also converts numbers to strings automatically:Click tabs to explore String-to-Number, String-to-Date, and reverse conversions.