How to get all the information about current date in Java?



Problem Description :


Write a program in that prints following information about current date in Java.

  • Day of month
  • Month number
  • Month name
  • Year
  • Day number of week
  • Day name
  • Week of month
  • Week of year
  • Hour in 12-hour format
  • Hour in 24-hour format
  • Minutes
  • Seconds
  • Milliseconds 

Concept :


We are using following method of Calendar class that is present in java.util.* package.

public int get(int field) -> In this method we are passing following Calendar class constants for getting required information.

  • static int DAY_OF_MONTH -> Provides Day of month.
  • static int MONTH -> Provides Month number, for getting month name we are using switch case.
  • static int YEAR -> Provodes Year.
  • static int DAY_OF_WEEK -> Provides Day number of week, for getting day name we are using switch case.
  • static int WEEK_OF_MONTH -> Provides Week number of month.
  • static int WEEK_OF_YEAR -> Provides Week number of year.
  • static int HOUR -> Provides Hour in 12-hour format.
  • static int HOUR_OF_DAY -> Provides Hour in 24-hour format.
  • static int MINUTE -> Provides Minutes.
  • static int SECOND -> Provides Seconds.
  • static int MILLISECOND -> Provides Milliseconds.


Recommended :





Java Program :




Output :


Output of Java program that prints every information about current date.
Output - How to print every information about current date in Java?


Similar Problem :


How to get all the information about any given date in Java?

Solution - This is very simple first of all Convert given Date to Calendar and rest is same as above.


References :



Thank you friends, I hope you have clearly understood the solution of this problem. If you have any doubt, suggestion or query please feel free to comment below. You can also discuss this solution in our forum.

Tags : Date and Time problems, Every information about date in Java, Solution in Java, Calendar, switch statement.

About Author:

I am simple guy with lot of ambitions. My main motive is to share whatever knowledge I have related to programming. With me you can easily learn how to solve any programming problem in Java.You can connect with me on social networking sites also.


Let's Get Connected: Linkedin | Facebook |

How to get all the information about current date in Java? How to get all the information about current date in Java? Reviewed by Rohit Agarwal on 12/08/2016 Rating: 5

24 comments:

  1. Until this moment, I thought that it is impossible to do. Fortunately, I found this page and everything seems clear to me now.

    ReplyDelete
  2. 5094BEzekiel37A5FApril 15, 2024 3:06 pm

    9A8B7
    ----
    ----
    ----
    ----
    ----
    ----
    ----
    matadorbet
    ----

    ReplyDelete

Please provide your valuable comments. If you have any suggestion please share with me I will work on it and if you have any question or doubt please ask, don't hesitate. I am your friend, i will clarify all your doubts.

Powered by Blogger.