{"id":116,"date":"2019-01-19T11:33:27","date_gmt":"2019-01-19T11:33:27","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/java\/?p=116"},"modified":"2019-03-02T04:37:27","modified_gmt":"2019-03-02T04:37:27","slug":"18-java-date-and-time-part-1","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/","title":{"rendered":"Java &#8211; Date and Time &#8211; Part 1"},"content":{"rendered":"<p>In this lesson, you will learn how to use date and time data in Java. The Date class is found in the java.util package. However this class covers both date and time values. So there is no separate time class.<\/p>\n<p>&nbsp;<\/p>\n<p>We would cover the following<\/p>\n<ol>\n<li><a href=\"#t1\">Date Constructor<\/a><\/li>\n<li><a href=\"#t2\">Methods of the Date Class<\/a><\/li>\n<li><a href=\"#t3\">Getting Current Date and Time<\/a><\/li>\n<li><a href=\"#t4\">Comparing Dates<\/a><\/li>\n<li><a href=\"#t5\">Formatting Dates using SimpleDateFormat<\/a><\/li>\n<li><a href=\"#t6\">SimpleDateFormat Codes<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t1\">1. Date Constructor<\/strong><\/h4>\n<p>The Date class provides both constructors and methods. You use the constructors to create new dates. Similarly, you use the methods to manipulated date data.<\/p>\n<p>I have provided the two constructors below. Also, description of each is provided as well.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Date ():<\/strong> You use this constructor to create a date object with the current date and time<\/p>\n<p><strong>Date (long milisec):<\/strong> You use this constructor to create new date as well. But this constructor accepts an argument. The argument is the number of miliseconds that have elapsed since 1, January 1970 midnight.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t2\">2. Methods of the Date Class<\/strong><\/h4>\n<p>We have various useful methods in the date class.<\/p>\n<p>&nbsp;<\/p>\n<table class=\"table table-bordered\" align=\"center\">\n<tbody>\n<tr style=\"background-color: #f7f6f3;\">\n<th>SN<\/th>\n<th>Methods\u00a0 and Description<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><b>boolean after(Date date)<\/b><\/p>\n<p>Returns true if the invoking Date object contains a date that is later than the one specified by date, otherwise, it returns false.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><b>boolean before(Date date)<\/b><\/p>\n<p>Returns true if the invoking Date object contains a date that is earlier than the one specified by date, otherwise, it returns false.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><b>Object clone( )<\/b><\/p>\n<p>Duplicates the invoking Date object.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td><b>int compareTo(Date date)<\/b><\/p>\n<p>This method compares the value of an object with that of date. It returns 0 if the values are equal. But a negative value if the object is earlier than the date. And a positive value is returned if the object is later than date.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5<\/td>\n<td><b>int compareTo(Object obj)<\/b><\/p>\n<p>This is similar to compareTo(Date) if obj is of class Date. If not, it throws a ClassCastException.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">6<\/td>\n<td><b>boolean equals(Object date)<\/b><\/p>\n<p>This method returns true if the a Date object contains the same time and date as the one specified by date parameter. If not, it returns false.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">7<\/td>\n<td><b>long getTime( )<\/b><\/p>\n<p>This method returns the number of milliseconds that have passed since 1st January 1970.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">8<\/td>\n<td><b>int hashCode( )<\/b><\/p>\n<p>This returns a hash code equivalent for an object.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">9<\/td>\n<td><b>void setTime(long time)<\/b><\/p>\n<p>You uses this to set the time and date as specified by time, which represents an elapsed time in milliseconds from midnight, 1st January 1970.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">10<\/td>\n<td><b>String toString( )<\/b><\/p>\n<p>This method converts a Date object into a string and returns the result. You probably will use it more often<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Listing 1.0: Methods of the Date Class<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t3\">3. Getting Current Date and Time<\/strong><\/h4>\n<p>You would oftentimes need to use the current date and time. So how do you get it? Very easy. You get it by just calling the toString method of a Date object. These are the steps:<\/p>\n<ul>\n<li>First you create a date object<\/li>\n<li>Second, you call the toString method<\/li>\n<\/ul>\n<p>You can however do these two operations in a single line. Look at the code below<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">java.util.Date<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">DateDemo<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">static<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">main<\/span><span style=\"color: #333333;\">(<\/span>String<span style=\"color: #333333;\">[]<\/span> args<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\r\n\t\t<span style=\"color: #888888;\">\/\/Create a new date<\/span>\r\n\t\tDate date <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> Date<span style=\"color: #333333;\">();<\/span>\r\n\t\t\r\n\t\t<span style=\"color: #888888;\">\/\/Display the value<\/span>\r\n\t\tSystem<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">out<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">println<\/span><span style=\"color: #333333;\">(<\/span>date<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">toString<\/span><span style=\"color: #333333;\">());<\/span>\t\t\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>Listing 1.0: Getting the current Date<\/p>\n<p>&nbsp;<\/p>\n<p>Notice from\u00a0 the code in Listing 1.0 that we import <strong>java.util.date.<\/strong> So the Date class is inside the <strong>java.util<\/strong> package. If you run the code above, then you will have the output below.<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">Sat Jan <span style=\"color: #0000dd; font-weight: bold;\">19<\/span> <span style=\"color: #0000dd; font-weight: bold;\">11<\/span><span style=\"color: #333333;\">:<\/span><span style=\"color: #0000dd; font-weight: bold;\">53<\/span><span style=\"color: #333333;\">:<\/span><span style=\"color: #0000dd; font-weight: bold;\">41<\/span> CET <span style=\"color: #0000dd; font-weight: bold;\">2019<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t4\">4. Comparing Dates<\/strong><\/h4>\n<p>You probably will need to compare two date to see if they are equal. Or maybe to see if one date precede the other. There are three ways to do this<\/p>\n<p>First Method: You can use the compareTo () method. This method is defined in the Comparable interface. It is however implemented by the Date class<\/p>\n<p>Second Method: You can use the getTime() method. This method gives you the number of miliseconds that have elapsed since 1st January, 1970. Get this value for both dates and then check if the two values are the same<\/p>\n<p>Third Method: You can use the methods before(), after() and equals(). This method are provided in the Date class.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t5\">5. Formatting Date Using SimpleDateFormat<\/strong><\/h4>\n<p>The SimpleDateFormat() allows you to format date in different formats.\u00a0 So you specify a pattern that you want the date to be formatted in. However, you first need to create SimpleDateFormat object.<\/p>\n<p>For example, the code in Listing 1.1 displays a date formatted using SimpleDateFormat.<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">java.text.SimpleDateFormat<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">java.util.Date<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">DateDemo<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">static<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">main<\/span><span style=\"color: #333333;\">(<\/span>String<span style=\"color: #333333;\">[]<\/span> args<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t\r\n\t\t\t<span style=\"color: #888888;\">\/\/Create a new date<\/span>\r\n\t\t\tDate date <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> Date<span style=\"color: #333333;\">();<\/span>\r\n\t\t\t\r\n\t\t\t<span style=\"color: #888888;\">\/\/Create a SimpleDateFormat<\/span>\r\n\t\t\tSimpleDateFormat ft <span style=\"color: #333333;\">=<\/span> \r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">new<\/span> <span style=\"color: #0066bb; font-weight: bold;\">SimpleDateFormat<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"E yyyy-MMM-dd 'at' hh:mm:ss a zzz\"<\/span><span style=\"color: #333333;\">);<\/span>\r\n\t\t\t\r\n\t\t\t<span style=\"color: #888888;\">\/\/Print the date<\/span>\r\n\t\t\tSystem<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">out<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">println<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"Today's date: \"<\/span> <span style=\"color: #333333;\">+<\/span> ft<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">format<\/span><span style=\"color: #333333;\">(<\/span>date<span style=\"color: #333333;\">));<\/span>\t\t\t\t\t\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>Listing 1.1: Printing current date using SimpleDateFormate<\/p>\n<p>&nbsp;<\/p>\n<p>I recommend you try to run this code yourself. If you do, you will have the output shown below. Also try to change things a bit and see what output you get. Next section explains the codes!<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">Today<span style=\"color: #ff0000; background-color: #ffaaaa;\">'<\/span>s <span style=\"color: #997700; font-weight: bold;\">date:<\/span> Sat <span style=\"color: #0000dd; font-weight: bold;\">2019<\/span><span style=\"color: #333333;\">-<\/span>Jan<span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">19<\/span> at <span style=\"color: #0000dd; font-weight: bold;\">12<\/span><span style=\"color: #333333;\">:<\/span><span style=\"color: #0000dd; font-weight: bold;\">12<\/span><span style=\"color: #333333;\">:<\/span><span style=\"color: #0000dd; font-weight: bold;\">04<\/span> PM CET\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t6\">6. SimpleDateFormate Codes<\/strong><\/h4>\n<p>You can find the the meaning of the codes in Table 1.1. I suggest you takes some time to go through. So you get your head around them. You also kind of gradually get used to them.<\/p>\n<p>&nbsp;<\/p>\n<table class=\"table table-bordered\" align=\"center\">\n<tbody>\n<tr style=\"background-color: #f7f6f3;\">\n<th>Character Code<\/th>\n<th>Brief description<\/th>\n<th>E.g<\/th>\n<\/tr>\n<tr>\n<td>G<\/td>\n<td>Era designator<\/td>\n<td>AD<\/td>\n<\/tr>\n<tr>\n<td>y<\/td>\n<td>Year in four digits<\/td>\n<td>2017<\/td>\n<\/tr>\n<tr>\n<td>M<\/td>\n<td>Month of year<\/td>\n<td>July or 07<\/td>\n<\/tr>\n<tr>\n<td>d<\/td>\n<td>Day of month<\/td>\n<td>11<\/td>\n<\/tr>\n<tr>\n<td>h<\/td>\n<td>Hour in A.M.\/P.M. (1~12)<\/td>\n<td>12<\/td>\n<\/tr>\n<tr>\n<td>H<\/td>\n<td>Hour in 24 hour format<\/td>\n<td>21<\/td>\n<\/tr>\n<tr>\n<td>m<\/td>\n<td>Minute in hour<\/td>\n<td>56<\/td>\n<\/tr>\n<tr>\n<td>s<\/td>\n<td>Second in minute<\/td>\n<td>45<\/td>\n<\/tr>\n<tr>\n<td>S<\/td>\n<td>Millisecond<\/td>\n<td>326<\/td>\n<\/tr>\n<tr>\n<td>E<\/td>\n<td>Day of week<\/td>\n<td>Wednesday<\/td>\n<\/tr>\n<tr>\n<td>D<\/td>\n<td>Day of year<\/td>\n<td>240<\/td>\n<\/tr>\n<tr>\n<td>F<\/td>\n<td>Day of week in month<\/td>\n<td>2 (second Mon. in May)<\/td>\n<\/tr>\n<tr>\n<td>w<\/td>\n<td>Week in year<\/td>\n<td>30<\/td>\n<\/tr>\n<tr>\n<td>W<\/td>\n<td>Week in month<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<td>a<\/td>\n<td>A.M.\/P.M. marker<\/td>\n<td>PM<\/td>\n<\/tr>\n<tr>\n<td>k<\/td>\n<td>Hour in 24 hour format<\/td>\n<td>24<\/td>\n<\/tr>\n<tr>\n<td>K<\/td>\n<td>Hour in A.M.\/P.M. (0~11)<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>z<\/td>\n<td>Time zone<\/td>\n<td>Eastern Standard Time<\/td>\n<\/tr>\n<tr>\n<td>&#8216;<\/td>\n<td>Escape for text<\/td>\n<td>Delimiter<\/td>\n<\/tr>\n<tr>\n<td>&#8220;<\/td>\n<td>Single quote<\/td>\n<td>`<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Listing 1.1: Table of SimpleDateFormat Codes<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this lesson, you will learn how to use date and time data in Java. The Date class is found in the java.util package. However &hellip; <\/p>\n","protected":false},"author":395,"featured_media":117,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-116","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java - Date and Time - Part 1 - Java Tutorials<\/title>\n<meta name=\"description\" content=\"In this lesson(Part 1) we learn about Date and time data in Java. We learn about creating dates, comparing dates and formatting dates\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java - Date and Time - Part 1 - Java Tutorials\" \/>\n<meta property=\"og:description\" content=\"In this lesson(Part 1) we learn about Date and time data in Java. We learn about creating dates, comparing dates and formatting dates\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/\" \/>\n<meta property=\"og:site_name\" content=\"Java Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2019-01-19T11:33:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-02T04:37:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/9\/2019\/01\/Date-and-Time-in-Java-Part-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"950\" \/>\n\t<meta property=\"og:image:height\" content=\"518\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/18-java-date-and-time-part-1\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/18-java-date-and-time-part-1\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\"},\"headline\":\"Java &#8211; Date and Time &#8211; Part 1\",\"datePublished\":\"2019-01-19T11:33:27+00:00\",\"dateModified\":\"2019-03-02T04:37:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/18-java-date-and-time-part-1\\\/\"},\"wordCount\":906,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/18-java-date-and-time-part-1\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/wp-content\\\/uploads\\\/sites\\\/9\\\/2019\\\/01\\\/Date-and-Time-in-Java-Part-1.jpg\",\"articleSection\":[\"Java Tutorial\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/18-java-date-and-time-part-1\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/18-java-date-and-time-part-1\\\/\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/18-java-date-and-time-part-1\\\/\",\"name\":\"Java - Date and Time - Part 1 - Java Tutorials\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/18-java-date-and-time-part-1\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/18-java-date-and-time-part-1\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/wp-content\\\/uploads\\\/sites\\\/9\\\/2019\\\/01\\\/Date-and-Time-in-Java-Part-1.jpg\",\"datePublished\":\"2019-01-19T11:33:27+00:00\",\"dateModified\":\"2019-03-02T04:37:27+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\"},\"description\":\"In this lesson(Part 1) we learn about Date and time data in Java. We learn about creating dates, comparing dates and formatting dates\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/18-java-date-and-time-part-1\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/18-java-date-and-time-part-1\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/18-java-date-and-time-part-1\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/wp-content\\\/uploads\\\/sites\\\/9\\\/2019\\\/01\\\/Date-and-Time-in-Java-Part-1.jpg\",\"contentUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/wp-content\\\/uploads\\\/sites\\\/9\\\/2019\\\/01\\\/Date-and-Time-in-Java-Part-1.jpg\",\"width\":950,\"height\":518,\"caption\":\"Date and Time in Java\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/18-java-date-and-time-part-1\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java &#8211; Date and Time &#8211; Part 1\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/#website\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/\",\"name\":\"Java Tutorials\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/author\\\/kindsonthegenius-2\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java - Date and Time - Part 1 - Java Tutorials","description":"In this lesson(Part 1) we learn about Date and time data in Java. We learn about creating dates, comparing dates and formatting dates","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:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/","og_locale":"en_US","og_type":"article","og_title":"Java - Date and Time - Part 1 - Java Tutorials","og_description":"In this lesson(Part 1) we learn about Date and time data in Java. We learn about creating dates, comparing dates and formatting dates","og_url":"https:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/","og_site_name":"Java Tutorials","article_published_time":"2019-01-19T11:33:27+00:00","article_modified_time":"2019-03-02T04:37:27+00:00","og_image":[{"width":950,"height":518,"url":"https:\/\/www.kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/9\/2019\/01\/Date-and-Time-in-Java-Part-1.jpg","type":"image\/jpeg"}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/#article","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/www.kindsonthegenius.com\/java\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2"},"headline":"Java &#8211; Date and Time &#8211; Part 1","datePublished":"2019-01-19T11:33:27+00:00","dateModified":"2019-03-02T04:37:27+00:00","mainEntityOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/"},"wordCount":906,"commentCount":0,"image":{"@id":"https:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/9\/2019\/01\/Date-and-Time-in-Java-Part-1.jpg","articleSection":["Java Tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/","url":"https:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/","name":"Java - Date and Time - Part 1 - Java Tutorials","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/java\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/#primaryimage"},"image":{"@id":"https:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/9\/2019\/01\/Date-and-Time-in-Java-Part-1.jpg","datePublished":"2019-01-19T11:33:27+00:00","dateModified":"2019-03-02T04:37:27+00:00","author":{"@id":"https:\/\/www.kindsonthegenius.com\/java\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2"},"description":"In this lesson(Part 1) we learn about Date and time data in Java. We learn about creating dates, comparing dates and formatting dates","breadcrumb":{"@id":"https:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/#primaryimage","url":"https:\/\/www.kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/9\/2019\/01\/Date-and-Time-in-Java-Part-1.jpg","contentUrl":"https:\/\/www.kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/9\/2019\/01\/Date-and-Time-in-Java-Part-1.jpg","width":950,"height":518,"caption":"Date and Time in Java"},{"@type":"BreadcrumbList","@id":"https:\/\/www.kindsonthegenius.com\/java\/18-java-date-and-time-part-1\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.kindsonthegenius.com\/java\/"},{"@type":"ListItem","position":2,"name":"Java &#8211; Date and Time &#8211; Part 1"}]},{"@type":"WebSite","@id":"https:\/\/www.kindsonthegenius.com\/java\/#website","url":"https:\/\/www.kindsonthegenius.com\/java\/","name":"Java Tutorials","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.kindsonthegenius.com\/java\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.kindsonthegenius.com\/java\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/www.kindsonthegenius.com\/java\/author\/kindsonthegenius-2\/"}]}},"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/posts\/116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/users\/395"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/comments?post=116"}],"version-history":[{"count":1,"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/posts\/116\/revisions"}],"predecessor-version":[{"id":118,"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/posts\/116\/revisions\/118"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/media\/117"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/media?parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/categories?post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/tags?post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}