![]() |
VOOZH | about |
In software development, we often work with dates and times. To accurately capture the current date and time is fundamental for various applications, such as scheduling tasks, tracking events, etc.
In Java, there is a built-in class known as the Date class and we can import java.time package to work with date and time API. Here we are supposed to print the current date and time. There can be multiple ways to print the current date and time.
java.time.LocalDateUsingjava.time.LocalTimejava.time.LocalDateTimeUsing java.time.ClockUsing java.sql.DateUsing Date Class in this method we will explore the date and time module provided by java.util.
Current date is Thu Nov 30 07:45:38 UTC 2023
getInstance() method is generally used to get the time, date or any required some belonging to Calendar year.
Tip: Whenever we require anything belonging to Calendar, Calendar class is one of naive base for sure approach to deal with date and time instances.
Day of week : 5 Day of year : 334 Week in Month : 5 Week in Year : 48 Day of Week in Month : 5 Hour : 7 Minute : 45 Second : 39 AM or PM : 0 Hour (24-hour clock) : 7
Using calendar and formatter class to print the current dates in a specific format.
Formatted Date : 04-01-2024 Parsed Date : Sat Feb 18 00:00:00 UTC 1995
In this method we will discuss various date and time methods provided by java.time which
Current date: 2024-01-04 Current time: 11:59:03.285876 Current date and time: 2024-01-04T11:59:03.286975
This method we will discuss the use of clock method to fetch date and time provided by java.time package.
Current instant: 2024-01-04T11:58:52.703945Z