Formatting Flashcards
How do we format date or time?
Using DateTimeFormatter
How can we set format of date or time using DateTimeFormatter?
DateTimeFormatter.ofPattern() or predefined DateTimeFormatter.ISO_LOCAL_TIME, DateTimeFormatter.ISO_LOCAL_DATE, DateTimeFormatter.ISO_LOCAL_DATE_TIME
What is potential pitfall when using predefined “ISO” values?
Mix of date instead of time, and vice versa
How do we use DateTimeFormatter on LocalDateTime
dateTime.format(DateTimeFormatter.ofPattern(“”))
What letters are used in date time patterns?
m, M, h, s, d, M, a
How do we format decimal numbers?
Using DecimalFormat
What is the difference between 0 and # in DecimalFormat pattern?
Values at # are omitted if missing, 0 are not - it shows 0
How do we format number using DecimalFormat ?
new DecimalFormat(“###.##”).format(number)
What class does DecimalFormat extend?
NumberFormat