The Calendar class
In this section, we're going to take a look at Java's Calendar
class. When writing Java code, we generally use the Calendar
class to refer to a specific moment in time.
The Calendar
class is actually a relatively new addition to the Java API. Previously, we used a class called Date
to perform the similar functionality. If you end up working on older Java code or are writing Java code that deals with a SQL or MySQL database, you'll probably end up using the Java Date
class at least occasionally. If this happens, don't panic; consult the Java documentation and you'll discover that there are some really great functions for swapping between Calendar
and Date
objects.
To see the power of Java's Calendar
class, let's jump into a Java program and instantiate it. Let's create a new program; first, import all the classes from the java.util
package because that's where the Calendar
class lives.
Next, we declare a new Calendar
object; I'm going to call it now
because our first goal...