Java provides a useful and versatile Date class in its java.time package. This class allows us to represent moments in time and dates, and manipulate them however we want with just a few lines of code.
Java makes working with these a breeze.
Creating a Date
Creating a date is pretty easy. Simply create a Date object and print it out:
If you're curious about what those characters do and if there are any others, here are all the characters that you can use when formatting your dates:
G: Era (AD/BC)
y: Year in four digits (2020)
M: Month (June)
d: Day in month (17)
h: Hour from 1-12
H: Hour from 0-23
m: Minute
s: Second
S: Millisecond
E: Day in week (Friday)
D: Day in year (100)
F: Day of week in month (2nd Friday in June)
w: Week in year (23)
W: Week in month (3)
a: AM/PM
k: Hour in day from 1-24
K: Hour from 0-11
Z: Timezone
Unix Time
Unix time is a concept in computer science that refers to the number of milliseconds that have elapsed since the arbitrarily decided midnight on January 1st, 1970.