How to get current date, month, year and day of week in Java program

Here is quick Java tip to get current date, month, year and day of week from Java program. Java provides a rich Date and Time API though having thread-safety issue but its rich in function and if used locally can give you all the date and time information which you need for your enterprise Java application. In last Java tutorial on Date and Time API we have seen how to get current date and time from different timezone using DateFormat and SimpleDateFormat classes and in this post we will get some more details like current month, year, day of week etc by using java.util.Calendar class.  Just keep in mind that Calendar instance should not be shared between multiple threads. Calendar class in Java provides different fields to get different information e.g. Calendar.DATE gives you current date while Calendar.MONTH gives you current month based on what type of Calendar you are using, which depends upon locale.
Read more »

0 Response to "How to get current date, month, year and day of week in Java program"

Posting Komentar