Java Date-Time Lab



The course is part of this learning path

Start course

In this course, we will talk about DateTime Class. 

Learning Objectives

  • LocalDate Class
  • LocalTime Class
  • LocalDateTime Class
  • Period Class
  • DateTime Formatting

Intended Audience

  • Anyone looking to get Oracle Java Certification
  • Those who want to learn the Java Programming language from scratch
  • Java developers who want to increase their knowledge
  • Beginners with no previous coding experience in Java programming
  • Those who want to learn tips and tricks in Oracle Certified Associate – Java SE 8 Programmer certification exams


  • No prior knowledge is required about the Java programming language
  • Basic computer knowledge

Hi there. In this section, we learned about date and time in Java. In general, the point you should pay attention to is this: Before Java 8, the date and calendar classes in the java.util package were used and the date and time were handled together in these classes. However, in Java 8 and later, Date-Time and DateTime classes in the java.time package started to be used instead of these classes. That is, a class was created for date operations, a separate class for time operations, and a separate class for operations involving both. Therefore, date-time questions that you may encounter, you need to determine from which class the created object was created, and then whether the values assigned to this object are related to date or time, because this is often overlooked. You should also pay attention to this when formatting the time and date. Assigning a time format to the date or assigning a date format to the time will cause an error. 

Also, this error will not be a compilation error, it will be a runtime exception error. Okay, don't forget this. Apart from these, you can access the packages in Java and the classes contained in these packages by using the link on the slide. I already shared this link with you. Now, let's briefly examine this page through the browser. When you click on the link I shared with you, you'll be directed to this page. This page consists of three parts. The upper left section is the section with the packages. The section just below shows the classes included in this package. This is the section where there are explanations about this package and the classes in the package. For example, let's click on the java.time.format package. As you can see, the classes in this package appear here. From here, let's click on the DateTimeFormatter class. Now on the right side, we can find information about this class. If you scroll down the page, you can see the table under the patterns for formatting and parsing heading where you can access the letters we used for the custom format and the meanings of these letters. For example, let's take a brief look at this table. 

We used the letter Y for year in the custom format. If you pay attention, we can see here that the letter Y is used for the year. It gives a year as the output. And for example, we can get output in this way. Again, the letter U can be used instead of the letter Y in the same way. Let's look at the letter M, which we use in the custom format and represents the month. We can see from here that the letter M represents the month, gives numbers or text as output and we can get results like this for example. Of course, we explained in the lesson that the type of these outputs depends on the number of letters you use. For example, if you use a single letter M, the month will be represented with a single number in this way. Well, if you use three letters M, you can understand that you will get an output like this. Yes, in this way it's possible to access the packages you have in mind, or the classes in these packages in detailed information about their use via the official document here. We can end the lesson here. See you in the next lesson.


About the Author
Learning Paths

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.

Covered Topics