{"id":3883,"date":"2017-08-05T10:41:15","date_gmt":"2017-08-05T10:41:15","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=3883"},"modified":"2021-03-21T06:16:38","modified_gmt":"2021-03-21T06:16:38","slug":"write-a-java-program-to-display-current-date-time","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/write-a-java-program-to-display-current-date-time\/","title":{"rendered":"Write a java program to display current Date and Time"},"content":{"rendered":"<h3>Code Listing<\/h3>\n<p>Let&#8217;s write a simple java program that displays the current date and time on the console window.<\/p>\n<pre>package com.testingdocs.datetime;\r\n\r\n\/\/DateDemo.java\r\n\/\/www.TestingDocs.com\r\n\r\nimport java.util.GregorianCalendar;\r\nimport java.util.Calendar;\r\n\r\npublic class DateDemo {\r\n    public static void main(String args[]) {\r\n        GregorianCalendar date = new GregorianCalendar();\r\n        int currentDay = date.get(Calendar.DAY_OF_MONTH);\r\n        int currentMonth = date.get(Calendar.MONTH);\r\n        int currentYear = date.get(Calendar.YEAR);\r\n        int hour = date.get(Calendar.HOUR);\r\n        int minute = date.get(Calendar.MINUTE);\r\n        int second = date.get(Calendar.SECOND);\r\n        System.out.println(\"Program Output----- \");\r\n        System.out.println(\"Current Date := \" +currentDay+ \"\/\" +\r\n(currentMonth+1)+ \"\/\" +currentYear);\r\n        System.out.println(\"Current Time := \"+ hour + \" : \" +\r\n minute + \" :\" +second);\r\n    }\r\n}\r\n\r\n<\/pre>\n<h3>Screenshot<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3888\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Current-Date-and-Time-Java-Program.png\" alt=\"Current Date and Time Java Program\" width=\"1729\" height=\"1031\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Current-Date-and-Time-Java-Program.png 1729w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Current-Date-and-Time-Java-Program-300x179.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Current-Date-and-Time-Java-Program-1024x611.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Current-Date-and-Time-Java-Program-768x458.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Current-Date-and-Time-Java-Program-1536x916.png 1536w\" sizes=\"auto, (max-width: 1729px) 100vw, 1729px\" \/><\/p>\n<h3>Program Output<\/h3>\n<p>Program Output&#8212;&#8211;<br \/>\nCurrent Date := 5\/8\/2017<br \/>\nCurrent Time := 4 : 14 :12<\/p>\n<!--themify_builder_content-->\n<div id=\"themify_builder_content-3883\" data-postid=\"3883\" class=\"themify_builder_content themify_builder_content-3883 themify_builder tf_clear\">\n    <\/div>\n<!--\/themify_builder_content-->\n","protected":false},"excerpt":{"rendered":"<p>Code Listing Let&#8217;s write a simple java program that displays the current date and time on the console window. package com.testingdocs.datetime; \/\/DateDemo.java \/\/www.TestingDocs.com import java.util.GregorianCalendar; import java.util.Calendar; public class DateDemo { public static void main(String args[]) { GregorianCalendar date = new GregorianCalendar(); int currentDay = date.get(Calendar.DAY_OF_MONTH); int currentMonth = date.get(Calendar.MONTH); int currentYear = date.get(Calendar.YEAR); int [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[],"class_list":["post-3883","post","type-post","status-publish","format-standard","hentry","category-java","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/3883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=3883"}],"version-history":[{"count":5,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/3883\/revisions"}],"predecessor-version":[{"id":19718,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/3883\/revisions\/19718"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=3883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=3883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=3883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}