{"id":78893,"date":"2020-06-01T10:00:34","date_gmt":"2020-06-01T04:30:34","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=78893"},"modified":"2020-06-01T10:00:34","modified_gmt":"2020-06-01T04:30:34","slug":"date-and-time-in-java","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/","title":{"rendered":"How to Get Date and Time in Java &#8211; Java Date Class"},"content":{"rendered":"<p>Date and Time play a very important role in our life and are important factors used in every technology in this world.<\/p>\n<p>It is considered a very important and critical factor in the transaction systems where a single millisecond can cause a change in the system.<\/p>\n<p>For example, take a scenario of Railway reservation system; If a user books a ticket for a seat in a train and at the same time another user tries to book the same seat.<\/p>\n<p>But the time when the first user requested was stored in the database and restricts any other user to book the same seat. Here is the major role of Date and Time.<\/p>\n<p>In this article, we will study how the Java programming language facilitates us with the functionality of Date and Time. Java provides Date class along with the methods to format the Date and Time and also to get the current date and time.<\/p>\n<p>Let\u2019s start discussing Date and Time in Java.<\/p>\n<h3>Date and Time in Java- The Date class<\/h3>\n<p>Java comes with the Date class that is located in the java.util package and provides many methods to perform operations with date and time.<\/p>\n<p>The Date class of Java implements the Cloneable, Serializable, and Comparable interfaces of Java.<\/p>\n<h3>Constructors of the Date class<\/h3>\n<p>There are also six java constructors of the Date class but four of them are deprecated and therefore only two of them are used. These two constructors are listed below with the description:<\/p>\n<p><strong>1. Date()<\/strong><\/p>\n<p>This is the non-parameterized constructor of the Date class and is used to initialize the Date class object with the current date and time.<\/p>\n<p><strong>2. Date(long millisec)<\/strong><\/p>\n<p>It is a parameterized constructor of the Date class and we pass one argument to it in the form of milliseconds.<\/p>\n<p>This constructor creates for us an object of the Date class for the given input milliseconds since midnight, January 1, 1970<\/p>\n<h3>Methods of Java Date class<\/h3>\n<table>\n<tbody>\n<tr>\n<td><b>S.N.<\/b><\/td>\n<td><b>Method<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">1<\/span><\/td>\n<td><span style=\"font-weight: 400\">boolean<\/span><b> after<\/b><span style=\"font-weight: 400\">(Date date)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method returns true if the current object of the Date class contains the date which is later than the date specified in the parameter of the method, otherwise, it returns false.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">2<\/span><\/td>\n<td><span style=\"font-weight: 400\">boolean <\/span><b>before<\/b><span style=\"font-weight: 400\">(Date date)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method returns true if the current object of the Date class contains the date which is earlier than the date specified in the parameter of the method, otherwise, it returns false.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">3<\/span><\/td>\n<td><span style=\"font-weight: 400\">Object<\/span><b> clone<\/b><span style=\"font-weight: 400\">( )<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method creates a duplicate copy of the invoking Date class object.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">4<\/span><\/td>\n<td><span style=\"font-weight: 400\">int <\/span><b>compareTo(Date date)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method is used to compare the value of the invoking object with the specified date. It returns 0 if the values are equal, a negative value if the invoking object is earlier than the date and a positive value if the invoking object is later than date.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">5<\/span><\/td>\n<td><span style=\"font-weight: 400\">int<\/span><b> compareTo(Object obj)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method works identical to the compareTo(Date) method if the object is of Date type. If it is not, then the method throws the ClassCastException.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">6<\/span><\/td>\n<td><span style=\"font-weight: 400\">boolean<\/span><b> equals<\/b><span style=\"font-weight: 400\">(Object date)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method returns true if the invoking object of the Date class contains the same time and date as the one specified by date, otherwise, it returns false.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">7<\/span><\/td>\n<td><span style=\"font-weight: 400\">long <\/span><b>getTime<\/b><span style=\"font-weight: 400\">( )<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method returns the number of milliseconds that have elapsed since January 1, 1970.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">8<\/span><\/td>\n<td><span style=\"font-weight: 400\">int<\/span><b> hashCode<\/b><span style=\"font-weight: 400\">( )<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method gives the hash code value for the invoking Date object.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">9<\/span><\/td>\n<td><span style=\"font-weight: 400\">void <\/span><b>setTime<\/b><span style=\"font-weight: 400\">(long time)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method is used to set the time and date as specified by time, which represents an elapsed time in milliseconds from midnight, January 1, 1970.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">10<\/span><\/td>\n<td><span style=\"font-weight: 400\">String<\/span><b> toString<\/b><span style=\"font-weight: 400\">( )<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the String representation of the invoking Date class object.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Getting Current Date and time of the system<\/h3>\n<p>We can easily retrieve the current date and time of our system using two ways:<\/p>\n<ol>\n<li>Using the Date class<\/li>\n<li>Using the Calendar class<\/li>\n<\/ol>\n<h4>1. Using Date class in Java<\/h4>\n<p>This is the easiest method to get the current date and time of the system. We can create the object of the Date class and call the toString() method from this object to get the current date and time.<\/p>\n<p><strong>Code to get the current date and time using the Date class:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.dateandtime;\nimport java.util.Date;\npublic class DateDemo {\n  public static void main(String args[]) {\n    \/\/ Instantiating a Date object\n    Date date = new Date();\n\n    \/\/ display time and date using toString() method\n    System.out.println(\"The current date and time is: \");\n    System.out.println(date.toString());\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nThe current date and time is:<br \/>\nTue Apr 07 03:20:26 IST 2020<\/p>\n<h4>2. Using Calendar class<\/h4>\n<p>We can also use the Calendar class to get the current date and time.<\/p>\n<p>We create the instance of the Calendar class using the getInstance() method and then call the getTime() method to get the current date and time.<\/p>\n<p><strong>Code to get the current date and time using the Calendar class:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.dateandtime;\nimport java.util.Date;\nimport java.util.Calendar;\npublic class CalendarDemo {\n  public static void main(String args[]) {\n    \/\/ Instantiating a Calendar object\n    Calendar c = Calendar.getInstance();\n    \/\/ displaying the  time and date using getTime()\n    System.out.println(\"The current date and time is: \");\n    System.out.println(c.getTime());\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nThe current date and time is:<br \/>\nTue Apr 07 03:29:04 IST 2020<\/p>\n<h3>Date Formatting Using SimpleDateFormat class<\/h3>\n<p>We can also get the Date and time in the desired format by using the SimpledateFormat class which is a concrete class that allows us to format and parse the date and time in the desired manner.<\/p>\n<p>This class is located in the java.text package.<\/p>\n<p><strong>Code to format the date and time using the SimpleDateFormat class:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.dateandtime;\nimport java.util.Date;\nimport java.text.DateFormat;\nimport java.text.SimpleDateFormat;\nimport java.util.Calendar;\n\npublic class GettingCurrentDate {\n  public static void main(String[] args) {\n    \/\/getting current date and time using Date class\n    System.out.println(\"Using Date class:\");\n    System.out.println(\"The formatted date and time is:\");\n    DateFormat df = new SimpleDateFormat(\"dd\/MM\/yy HH:mm:ss\");\n    Date dateobj = new Date();\n    System.out.println(df.format(dateobj));\n\n    \/\/getting current date time using calendar class \n    System.out.println(\"\\nUsing Calendar class:\");\n    System.out.println(\"The formatted date and time is:\");\n    Calendar calobj = Calendar.getInstance();\n    System.out.println(df.format(calobj.getTime()));\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nUsing Date class:<br \/>\nThe formatted date and time is:<br \/>\n07\/04\/20 04:10:28<\/p>\n<p>Using Calendar class:<br \/>\nThe formatted date and time is:<br \/>\n07\/04\/20 04:10:28<\/p>\n<p>So, this is how we can get the formatted date and time.<\/p>\n<h3>SimpleDateFormat Format Codes<\/h3>\n<p>We can also use some codes to specify the time format using a time pattern string. There are some ASCII letters that are reserved as pattern letters, which are listed in the below table with examples:<\/p>\n<table style=\"height: 1258px\" width=\"726\">\n<tbody>\n<tr>\n<td><b>Character<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<td><b>Example<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">G<\/span><\/td>\n<td><span style=\"font-weight: 400\">Era designator<\/span><\/td>\n<td><span style=\"font-weight: 400\">AD or BC<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">y<\/span><\/td>\n<td><span style=\"font-weight: 400\">Year in four digits<\/span><\/td>\n<td><span style=\"font-weight: 400\">2019<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">M<\/span><\/td>\n<td><span style=\"font-weight: 400\">Month in year<\/span><\/td>\n<td><span style=\"font-weight: 400\">March or 03<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">d<\/span><\/td>\n<td><span style=\"font-weight: 400\">Day in month<\/span><\/td>\n<td><span style=\"font-weight: 400\">25<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">h<\/span><\/td>\n<td><span style=\"font-weight: 400\">Hour in A.M.\/P.M. (1~12)<\/span><\/td>\n<td><span style=\"font-weight: 400\">8<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">H<\/span><\/td>\n<td><span style=\"font-weight: 400\">Hour in day (0~23)<\/span><\/td>\n<td><span style=\"font-weight: 400\">20<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">m<\/span><\/td>\n<td><span style=\"font-weight: 400\">Minute in hour<\/span><\/td>\n<td><span style=\"font-weight: 400\">48<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">s<\/span><\/td>\n<td><span style=\"font-weight: 400\">Second in minute<\/span><\/td>\n<td><span style=\"font-weight: 400\">59<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">S<\/span><\/td>\n<td><span style=\"font-weight: 400\">Millisecond<\/span><\/td>\n<td><span style=\"font-weight: 400\">238<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">E<\/span><\/td>\n<td><span style=\"font-weight: 400\">Day in week<\/span><\/td>\n<td><span style=\"font-weight: 400\">Friday<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">D<\/span><\/td>\n<td><span style=\"font-weight: 400\">Day in year<\/span><\/td>\n<td><span style=\"font-weight: 400\">250<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">F<\/span><\/td>\n<td><span style=\"font-weight: 400\">Day of week in month<\/span><\/td>\n<td><span style=\"font-weight: 400\">2 (second Wed. in July)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">w<\/span><\/td>\n<td><span style=\"font-weight: 400\">Week in year<\/span><\/td>\n<td><span style=\"font-weight: 400\">25<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">W<\/span><\/td>\n<td><span style=\"font-weight: 400\">Week in month<\/span><\/td>\n<td><span style=\"font-weight: 400\">3<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">a<\/span><\/td>\n<td><span style=\"font-weight: 400\">A.M.\/P.M. marker<\/span><\/td>\n<td><span style=\"font-weight: 400\">PM<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">k<\/span><\/td>\n<td><span style=\"font-weight: 400\">Hour in day (1~24)<\/span><\/td>\n<td><span style=\"font-weight: 400\">24<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">K<\/span><\/td>\n<td><span style=\"font-weight: 400\">Hour in A.M.\/P.M. (0~11)<\/span><\/td>\n<td><span style=\"font-weight: 400\">10<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">z<\/span><\/td>\n<td><span style=\"font-weight: 400\">Time zone<\/span><\/td>\n<td><span style=\"font-weight: 400\">Indian Standard Time<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">&#8216;<\/span><\/td>\n<td><span style=\"font-weight: 400\">Escape for text<\/span><\/td>\n<td><span style=\"font-weight: 400\">Delimiter<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">&#8220;<\/span><\/td>\n<td><span style=\"font-weight: 400\">Single quote<\/span><\/td>\n<td><span style=\"font-weight: 400\">`<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Let&#8217;s see an example where we have used some of the codes in the program:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.dateandtime;\nimport java.util. * ;\nimport java.text. * ;\npublic class FormatCodesDemo {\n  public static void main(String args[]) {\n    Date date = new Date();\n    SimpleDateFormat formatObj = new SimpleDateFormat(\"E W yyyy.MM.dd 'at' hh:mm:ss a zzz\");\n    System.out.println(\"Current Date: \" + formatObj.format(date));\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nCurrent Date: Tue 2 2020.04.07 at 05:04:48 PM IST<\/p>\n<h3>Java Date and Time Conversion Characters<\/h3>\n<table style=\"height: 1973px\" width=\"741\">\n<tbody>\n<tr>\n<td><b>Character<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<td><b>Example<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">c<\/span><\/td>\n<td><span style=\"font-weight: 400\">Complete date and time<\/span><\/td>\n<td><span style=\"font-weight: 400\">Wed April 08 09:06:54 IST 2020<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">F<\/span><\/td>\n<td><span style=\"font-weight: 400\">ISO 8601 date<\/span><\/td>\n<td><span style=\"font-weight: 400\">2020-08-09<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">D<\/span><\/td>\n<td><span style=\"font-weight: 400\">U.S. formatted date (month\/day\/year)<\/span><\/td>\n<td><span style=\"font-weight: 400\">12\/29\/2014<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">T<\/span><\/td>\n<td><span style=\"font-weight: 400\">24-hour time<\/span><\/td>\n<td><span style=\"font-weight: 400\">17:05:18<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">r<\/span><\/td>\n<td><span style=\"font-weight: 400\">12-hour time<\/span><\/td>\n<td><span style=\"font-weight: 400\">03:45:19 pm<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">R<\/span><\/td>\n<td><span style=\"font-weight: 400\">24-hour time, no seconds<\/span><\/td>\n<td><span style=\"font-weight: 400\">18:54<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Y<\/span><\/td>\n<td><span style=\"font-weight: 400\">Four-digit year (with leading zeroes)<\/span><\/td>\n<td><span style=\"font-weight: 400\">2019<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">y<\/span><\/td>\n<td><span style=\"font-weight: 400\">Last two digits of the year (with leading zeroes)<\/span><\/td>\n<td><span style=\"font-weight: 400\">19<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">C<\/span><\/td>\n<td><span style=\"font-weight: 400\">First two digits of the year (with leading zeroes)<\/span><\/td>\n<td><span style=\"font-weight: 400\">20<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">B<\/span><\/td>\n<td><span style=\"font-weight: 400\">Full month name<\/span><\/td>\n<td><span style=\"font-weight: 400\">June<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">b<\/span><\/td>\n<td><span style=\"font-weight: 400\">Abbreviated month name<\/span><\/td>\n<td><span style=\"font-weight: 400\">Mar<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">m<\/span><\/td>\n<td><span style=\"font-weight: 400\">Two-digit month (with leading zeroes)<\/span><\/td>\n<td><span style=\"font-weight: 400\">02<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">d<\/span><\/td>\n<td><span style=\"font-weight: 400\">Two-digit day (with leading zeroes)<\/span><\/td>\n<td><span style=\"font-weight: 400\">03<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">e<\/span><\/td>\n<td><span style=\"font-weight: 400\">Two-digit day (without leading zeros)<\/span><\/td>\n<td><span style=\"font-weight: 400\">8<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">A<\/span><\/td>\n<td><span style=\"font-weight: 400\">Full weekday name<\/span><\/td>\n<td><span style=\"font-weight: 400\">Saturday<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">a<\/span><\/td>\n<td><span style=\"font-weight: 400\">Abbreviated weekday name<\/span><\/td>\n<td><span style=\"font-weight: 400\">Sat<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">j<\/span><\/td>\n<td><span style=\"font-weight: 400\">Three-digit day of year (with leading zeroes)<\/span><\/td>\n<td><span style=\"font-weight: 400\">068<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">H<\/span><\/td>\n<td><span style=\"font-weight: 400\">Two-digit hour (with leading zeroes), between 00 and 23<\/span><\/td>\n<td><span style=\"font-weight: 400\">20<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">k<\/span><\/td>\n<td><span style=\"font-weight: 400\">Two-digit hour (without leading zeros), between 0 and 23<\/span><\/td>\n<td><span style=\"font-weight: 400\">18<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">I<\/span><\/td>\n<td><span style=\"font-weight: 400\">Two-digit hour (with leading zeros), between 01 and 12<\/span><\/td>\n<td><span style=\"font-weight: 400\">06<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">l<\/span><\/td>\n<td><span style=\"font-weight: 400\">Two-digit hour (without leading zeros), between 1 and 12<\/span><\/td>\n<td><span style=\"font-weight: 400\">6<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">M<\/span><\/td>\n<td><span style=\"font-weight: 400\">Two-digit minutes (with leading zeroes)<\/span><\/td>\n<td><span style=\"font-weight: 400\">05<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">S<\/span><\/td>\n<td><span style=\"font-weight: 400\">Two-digit seconds (with leading zeroes)<\/span><\/td>\n<td><span style=\"font-weight: 400\">19<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">L<\/span><\/td>\n<td><span style=\"font-weight: 400\">Three-digit milliseconds (with leading zeroes)<\/span><\/td>\n<td><span style=\"font-weight: 400\">047<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">N<\/span><\/td>\n<td><span style=\"font-weight: 400\">Nine-digit nanoseconds (with leading zeroes)<\/span><\/td>\n<td><span style=\"font-weight: 400\">047000000<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">P<\/span><\/td>\n<td><span style=\"font-weight: 400\">Uppercase morning or afternoon marker<\/span><\/td>\n<td><span style=\"font-weight: 400\">PM<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">p<\/span><\/td>\n<td><span style=\"font-weight: 400\">Lowercase morning or afternoon marker<\/span><\/td>\n<td><span style=\"font-weight: 400\">pm<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">z<\/span><\/td>\n<td><span style=\"font-weight: 400\">RFC 822 numeric offset from GMT<\/span><\/td>\n<td><span style=\"font-weight: 400\">-0800<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Z<\/span><\/td>\n<td><span style=\"font-weight: 400\">Time zone<\/span><\/td>\n<td><span style=\"font-weight: 400\">IST<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">s<\/span><\/td>\n<td><span style=\"font-weight: 400\">Seconds since 1970-01-01 00:00:00 GMT<\/span><\/td>\n<td><span style=\"font-weight: 400\">1078884319<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Q<\/span><\/td>\n<td><span style=\"font-weight: 400\">Milliseconds since 1970-01-01 00:00:00 GMT<\/span><\/td>\n<td><span style=\"font-weight: 400\">1078884319047<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Date Formatting Using printf<\/h3>\n<p>We can also format the date using the printf method. We have to use a two-letter format, starting with t and ending in any one of the letters of the above table.<\/p>\n<p>Let\u2019s understand this concept with a program:<\/p>\n<p><strong>Code to format the date using the printf method:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.dateandtime;\nimport java.util.Date;\npublic class DateDemo {\n  public static void main(String args[]) {\n    \/\/ Instantiating a Date object\n    Date date = new Date();\n\n    \/\/ displaying time and date\n    String string = String.format(\"Current Date\/Time is: %tc\", date);\n    \/\/Using the printf method\n    System.out.printf(string);\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nCurrent Date\/Time is: Tue Apr 07 05:20:59 IST 2020<\/p>\n<p>You can also use the &lt;flag alternatively. This is shown in below example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.dateandtime;\nimport java.util.Date;\npublic class DateDemo {\n  public static void main(String args[]) {\n    \/\/ Instantiate a Date object\n    Date date = new Date();\n\n    \/\/ display formatted date\n    System.out.printf(\"%s %tB %&lt;te, %&lt;tY\", \"Today's date:\", date);\n    System.out.printf(\"%s %tr \", \"\\nCurrent time:\", date);\n    System.out.printf(\"%s %tZ \", \"\\nCurrent Zone:\", date);\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nToday&#8217;s date: April 7, 2020<br \/>\nCurrent time: 05:35:47 PM<br \/>\nCurrent Zone: IST<\/p>\n<h3>Parsing Strings into Dates<\/h3>\n<p>There are also some additional methods in SimpleDateFormat; one of them is the parse() method that is used to parse a string according to the format stored in the given SimpleDateFormat object.<\/p>\n<p><strong>Code to parse the String into date:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.dateandtime;\nimport java.util. * ;\nimport java.text. * ;\n\npublic class DateDemo {\n  public static void main(String args[]) {\n    SimpleDateFormat ft = new SimpleDateFormat(\"yyyy-MM-dd\");\n    String input = \"2020-07-04\";\n\n    System.out.println(\"Input string is: \" + input);\n\n    Date date;\n    try {\n      date = ft.parse(input);\n      System.out.println(\"Parsed string is :\");\n      System.out.println(date);\n    }\n    catch(ParseException e) {\n      System.out.println(\"Unparseable string\");\n    }\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nInput string is: 2020-07-04<br \/>\nParsed string is :<br \/>\nSat Jul 04 00:00:00 IST 2020<\/p>\n<h3>Sleeping for a While<\/h3>\n<p>We can also use the sleep() method of Thread class to sleep for any duration of time starting from one ms to the lifetime of your computer.<\/p>\n<p>For example, in the below code the program will sleep for 5 seconds:<\/p>\n<p><strong>Code to sleep for a while:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.dateandtime;\nimport java.util. * ;\npublic class SleepDemo {\n  public static void main(String args[]) {\n    try {\n      System.out.println(\"Before sleeping:\");\n      System.out.println(new Date());\n      \/\/sleeping for 5 seconds \n      Thread.sleep(5000);\n      System.out.println(\"After sleeping for 5 seconds:\");\n      System.out.println(new Date());\n    }\n    catch(Exception e) {\n      System.out.println(\"Failed!\");\n    }\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nBefore sleeping:<br \/>\nTue Apr 07 05:07:23 IST 2020<br \/>\nAfter sleeping for 5 seconds:<br \/>\nTue Apr 07 12:07:28 IST 2020<\/p>\n<h3>GregorianCalendar Class<\/h3>\n<p>The GregorianCalendar is a concrete implementation of the Calendar class that we studied in the previous section of this article.<\/p>\n<p>The GregorianCalendar class is initialized with the current date and time with the help of getInstance() method of the Calendar class. It\u00a0 defines two fields: AD(After Death) and BC(Before Christ).<\/p>\n<p>These two fields represent the two eras defined by the real-life Gregorian calendar.<\/p>\n<p>There are some constructors of the GregorianCalendar class which are\u2212<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>S.N.<\/b><\/td>\n<td><b>Constructor\u00a0<\/b><\/td>\n<td><b> Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">1<\/span><\/td>\n<td><span style=\"font-weight: 400\">GregorianCalendar()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Constructs a default GregorianCalendar using the current time in the default time zone with the default locale.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">2<\/span><\/td>\n<td><span style=\"font-weight: 400\">GregorianCalendar(int year, int month, int date)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Constructs a GregorianCalendar with the given date set in the default time zone with the default locale.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">3<\/span><\/td>\n<td><span style=\"font-weight: 400\">GregorianCalendar(int year, int month, int date, int hour, int minute)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">4<\/span><\/td>\n<td><span style=\"font-weight: 400\">GregorianCalendar(int year, int month, int date, int hour, int minute, int second)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">5<\/span><\/td>\n<td><span style=\"font-weight: 400\">GregorianCalendar(Locale aLocale)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Constructs a GregorianCalendar based on the current time in the default time zone with the given locale.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">6<\/span><\/td>\n<td><span style=\"font-weight: 400\">GregorianCalendar(TimeZone zone)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Constructs a GregorianCalendar based on the current time in the given time zone with the default locale.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">7<\/span><\/td>\n<td><span style=\"font-weight: 400\">GregorianCalendar(TimeZone zone, Locale aLocale)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Constructs a GregorianCalendar based on the current time in the given time zone with the given locale.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>GregorianCalendar Support Methods<\/h4>\n<table>\n<tbody>\n<tr>\n<td><b>S.N.<\/b><\/td>\n<td><b>Method\u00a0<\/b><\/td>\n<td><b> Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">1<\/span><\/td>\n<td><span style=\"font-weight: 400\">void add(int field, int amount)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Adds the specified (signed) amount of time to the given time field, based on the calendar&#8217;s rules.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">2<\/span><\/td>\n<td><span style=\"font-weight: 400\">protected void computeFields()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Converts UTC as milliseconds to time field values.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">3<\/span><\/td>\n<td><span style=\"font-weight: 400\">protected void computeTime()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Overrides Calendar Converts time field values to UTC as milliseconds.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">4<\/span><\/td>\n<td><span style=\"font-weight: 400\">boolean equals(Object obj)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compare this GregorianCalendar to an object reference.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">5<\/span><\/td>\n<td><span style=\"font-weight: 400\">int get(int field)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Gets the value for a given time field.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">6<\/span><\/td>\n<td><span style=\"font-weight: 400\">int getActualMaximum(int field)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the maximum value that this field could have, given the current date.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">7<\/span><\/td>\n<td><span style=\"font-weight: 400\">int getActualMinimum(int field)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the minimum value that this field could have, given the current date.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">8<\/span><\/td>\n<td><span style=\"font-weight: 400\">int getGreatestMinimum(int field)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the highest minimum value for the given field if it varies.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">9<\/span><\/td>\n<td><span style=\"font-weight: 400\">Date getGregorianChange()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Gets the Gregorian Calendar change date.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">10<\/span><\/td>\n<td><span style=\"font-weight: 400\">int getLeastMaximum(int field)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the lowest maximum value for the given field if it varies.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">11<\/span><\/td>\n<td><span style=\"font-weight: 400\">int getMaximum(int field)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns maximum value for the given field.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">12<\/span><\/td>\n<td><span style=\"font-weight: 400\">Date getTime()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Gets this Calendar&#8217;s current time.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">13<\/span><\/td>\n<td><span style=\"font-weight: 400\">long getTimeInMillis()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Get this Calendar&#8217;s current time as a long.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">14<\/span><\/td>\n<td><span style=\"font-weight: 400\">TimeZone getTimeZone()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Gets the time zone.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">15<\/span><\/td>\n<td><span style=\"font-weight: 400\">int getMinimum(int field)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns minimum value for the given field.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">16<\/span><\/td>\n<td><span style=\"font-weight: 400\">int hashCode()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Overrides hashCode.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">17<\/span><\/td>\n<td><span style=\"font-weight: 400\">boolean isLeapYear(int year)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Determines if the given year is a leap year.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">18<\/span><\/td>\n<td><span style=\"font-weight: 400\">void roll(int field, boolean up)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Adds or subtracts (up\/down) a single unit of time on the given time field without changing larger fields.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">19<\/span><\/td>\n<td><span style=\"font-weight: 400\">void set(int field, int value)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Sets the time field with the given value.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">20<\/span><\/td>\n<td><span style=\"font-weight: 400\">void set(int year, int month, int date)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Sets the values for the fields year, month, and date.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">21<\/span><\/td>\n<td><span style=\"font-weight: 400\">void set(int year, int month, int date, int hour, int minute)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Sets the values for the fields year, month, date, hour, and minute.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">22<\/span><\/td>\n<td><span style=\"font-weight: 400\">void set(int year, int month, int date, int hour, int minute, int second)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Sets the values for the fields year, month, date, hour, minute, and second.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">23<\/span><\/td>\n<td><span style=\"font-weight: 400\">void setGregorianChange(Date date)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Sets the GregorianCalendar change date.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">24<\/span><\/td>\n<td><span style=\"font-weight: 400\">void setTime(Date date)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Sets this Calendar&#8217;s current time with the given Date.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">25<\/span><\/td>\n<td><span style=\"font-weight: 400\">void setTimeInMillis(long millis)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Sets this Calendar&#8217;s current time from the given long value.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">26<\/span><\/td>\n<td><span style=\"font-weight: 400\">void setTimeZone(TimeZone value)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Sets the time zone with the given time zone value.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">27<\/span><\/td>\n<td><span style=\"font-weight: 400\">String toString()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns a string representation of this calendar.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Code to understand the Gregorgian Calendar:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.dateandtime;\nimport java.util. * ;\npublic class GregorianCalendar Demo {\n  public static void main(String args[]) {\n    String months[] = {\n      \"Jan\",\n      \"Feb\",\n      \"Mar\",\n      \"Apr\",\n      \"May\",\n      \"Jun\",\n      \"Jul\",\n      \"Aug\",\n      \"Sep\",\n      \"Oct\",\n      \"Nov\",\n      \"Dec\"\n    };\n\n    int year;\n\n    GregorianCalendar gCalendar = new GregorianCalendar();\n\n    \/\/Display the current time and date information.\n    System.out.print(\"Today is: \");\n    System.out.print(months[gCalendar.get(Calendar.MONTH)]);\n    System.out.print(\" \" + gCalendar.get(Calendar.DATE) + \" \");\n    System.out.println(year = gCalendar.get(Calendar.YEAR));\n    System.out.print(\"Current time: \");\n    System.out.print(gCalendar.get(Calendar.HOUR) + \":\");\n    System.out.print(gCalendar.get(Calendar.MINUTE) + \":\");\n    System.out.println(gCalendar.get(Calendar.SECOND));\n\n    \/\/ Test if the current year is a leap year\n    if (gCalendar.isLeapYear(year)) {\n      System.out.println(\"The current year is a leap year\");\n    }\n    else {\n      System.out.println(\"The current year is not a leap year\");\n    }\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nToday is: Apr 7 2020<br \/>\nTime: 18:6:45<br \/>\nThe current year is a leap year<\/p>\n<h3>Conclusion<\/h3>\n<p>Here we come to the end of the article on Date and Time in Java. The Date class of java.util package plays a very important role in performing operations with date and time.<\/p>\n<p>We can use the SimpleFormatClass and its codes to format the date in the desired manner. We can also sleep the system for some seconds using the sleep method of Thread class.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Date and Time play a very important role in our life and are important factors used in every technology in this world. It is considered a very important and critical factor in the transaction&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":78948,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[2734,2735,2736,2737,2738,2739,2740,2741],"class_list":["post-78893","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-date-and-time-in-java","tag-date-time-format-java","tag-java-date-and-time","tag-java-date-class","tag-java-date-examples","tag-java-datetime","tag-java-datetime-format","tag-time-in-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Get Date and Time in Java - Java Date Class - TechVidvan<\/title>\n<meta name=\"description\" content=\"Date and Time in Java - Java Date Class and methods, how to get current date and time of the system, date formatting, Date and Time Conversion Characters\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Get Date and Time in Java - Java Date Class - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Date and Time in Java - Java Date Class and methods, how to get current date and time of the system, date formatting, Date and Time Conversion Characters\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-01T04:30:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Java-date-time.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Get Date and Time in Java - Java Date Class - TechVidvan","description":"Date and Time in Java - Java Date Class and methods, how to get current date and time of the system, date formatting, Date and Time Conversion Characters","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/","og_locale":"en_US","og_type":"article","og_title":"How to Get Date and Time in Java - Java Date Class - TechVidvan","og_description":"Date and Time in Java - Java Date Class and methods, how to get current date and time of the system, date formatting, Date and Time Conversion Characters","og_url":"https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-06-01T04:30:34+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Java-date-time.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"How to Get Date and Time in Java &#8211; Java Date Class","datePublished":"2020-06-01T04:30:34+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/"},"wordCount":2150,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Java-date-time.jpg","keywords":["date and time in java","date time format java","Java Date and Time","java date class","Java Date examples","java datetime","java datetime format","time in java"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/","url":"https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/","name":"How to Get Date and Time in Java - Java Date Class - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Java-date-time.jpg","datePublished":"2020-06-01T04:30:34+00:00","description":"Date and Time in Java - Java Date Class and methods, how to get current date and time of the system, date formatting, Date and Time Conversion Characters","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Java-date-time.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Java-date-time.jpg","width":802,"height":420,"caption":"Date and Time in java"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/date-and-time-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"How to Get Date and Time in Java &#8211; Java Date Class"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/78893","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=78893"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/78893\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/78948"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=78893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=78893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=78893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}