Dates Tutorial in java in detail with full programs

You are here : Home / Core Java Tutorials

Creating Date >

Creating Date in java using Calendar, GregorianCalendar and java.util.Date | Getting Year, Month, Date, Hour, Minute, Second from current date

Convert Calendar and GregorianCalendar to Date | Convert Date to Calendar and GregorianCalendar in java

Creating Date manually - by passing users parameter>

Forming date MANUALLY using java.util.Date’s constructor, GregorianCalendar’s constructor and set method in java

Convert String to Date>

Using SimpleDateFormat to convert String to Date - pass date, month, year, hour, minute, second, day, Am/Pm(E), time zone(z) || Enabling strict parsing of String by setting SimpleDateFormat’s setLenient(false)

Convert Date to String>

Using SimpleDateFormat to convert Date to String - use dd-MM-yyyy and dd-MM-yyyy hh:mm:ss format

Date comparison>

Date comparison using Date and Calendars’s before(), after() and equals() method | Also using Date.compareTo() method

Adding and subtracting from Dates>

Adding and subtracting days, month, year, hour, second, minutes from Date (using GregorianCalendar) | Adding days to manually created Date

Difference between two Dates>

Difference between two dates in days, hours, minutes, seconds, milliSeconds- where dates are manually created using dd-MM-yyyy and dd-MM-yyyy hh:mm:ss format

Check whether a given date lies between other two dates

2 approaches to check whether difference between given two dates is greater than specified number of days or not

Must read for you :