Home » Core Java » util » Page 27

util

Get Date

With this example we are going to demonstrate how to get a Date in Java. The class Date represents a specific instant in time, with millisecond precision. In short, to get a Date object you should: Create a new Date object, using the Date() constructor. The constructor allocates a Date object and initializes it so that it represents the time ...

Read More »

Date from specific time

This is an example of how to get a Date from a specific time. The class Date represents a specific instant in time, with millisecond precision. Getting a Date from a specific long time implies that you should: Create a new Date object, using the Date(long date) constructor, with a long parameter. The constructor allocates a Date object and initializes ...

Read More »

Convert Date to millisec

In this example we shall show you how to convert a Date to millisec, that means get the long number of millisec that represent a Date object. A Date object represents a specific instant in time, with millisecond precision. To convert a Date to millisec one should perform the following steps: Create a new Date object, using the Date() constructor, ...

Read More »

Compare Date objects with compareTo method

With this example we are going to demonstrate how to compare Date objects with compareTo method of the Date class. In short, to compare a Date object with another you should: Create a new Date object, using the Date() constructor, that allocates a Date object and initializes it so that it represents the time at which it was allocated, measured ...

Read More »

Compare Date objects with before method

This is an example of how to compare Date objects with before(Date when) API method of Date. Comparing a Date with another Date using before(Date when) method implies that you should: Create a new Date object, using the Date() constructor, that allocates a Date object and initializes it so that it represents the time at which it was allocated, measured ...

Read More »

Compare Date objects with after method

In this example we shall show you how to compare Date objects with after(Date when) method of Date, that tests if a Date is after the specified one. To compare a Date object with another Date object, using after(Date when) API method of Date one should perform the following steps: Use the simple Date() constructor, to allocate a Date object ...

Read More »

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 »