Home » Core Java » util » Calendar

Calendar

Get week of month and year

With this example we are going to demonstrate how to get the week of month and year from a Calendar object. The Calendar class is an abstract class that provides methods for converting between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR. It also provides methods for manipulating the calendar fields, ...

Read More »

Get time in millis using Calendar

This is an example of how to get the time in millis, using the abstract Calendar class, that provides methods for converting between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR. Getting the time in milliseconds with Calendar implies that you should: Use getInstance() API method of Calendar, in order to ...

Read More »

Get current TimeZone using Calendar

In this example we shall show you how to get the current TimeZone using Calendar. The Calendar is an abstract class that provides methods for converting between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR. To get the current TimeZone using Calendar one should perform the following steps: Use getInstance() API ...

Read More »

Compare Dates with before method

With this example we are going to demonstrate how to compare Dates with before(Object when) method of the Calendar class. In short, to compare a Calendar to another one with before(Object when) method of Calendar you should: Use getInstance() API method of Calendar, in order to get two Calendar objects, using the default time zone and locale. Use set(int field, ...

Read More »

Compare Dates with after method

This is an example of how to compare Dates with after(Object when) method of the Calendar class. Comparing a Calendar object to another using after(Object when) method of Calendar implies that you should: Use getInstance() API method of Calendar, in order to get two Calendar objects, using the default time zone and locale. Use set(int field, int value) API method ...

Read More »

Add/Subtract Hours from Date with Calendar

In this example we shall show you how to add and substract Hours from a Date with the Calendar class. Using this abstract class we can convert between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR. To add and substract Hours from Date with the Calendar one should perform the following ...

Read More »

Add/Subtract Months from Date with Calendar

With this example we are going to demonstrate how to add and subtract Months from a Date using the Calendar class, that allows us to convert between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR. In short, to add and subtract Months from a Date using the Calendar class you should: ...

Read More »

Add/Subtract Days from Date with Calendar

This is an example of how to add and subtract Days from a Date using the Calendar, that provides methods to convert between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR. Adding and subtracting Days from a Date using the Calendar implies that you should: Create a new Calendar object, using ...

Read More »