Date

This component simplifies working with dates. The Date identifier is the name you want your date object to have and Format String is the way you would like your date to be represented when printed out to a String. For a complete list of format expressions use the helper icon next to the format field.

Usage

The easiest way to use it is to use the default values in the dialog which will result in this:

IDate date1 = new IDate("yyyy-MM-dd HH:mm:ss");

We now have a date object with the current date and time. If we need this as a String we would do:

String currentDateAsString = date1.toString();

Adding milliseconds

If you need milliseconds to your date use this format:

IDate date1 = new IDate("yyyy-MM-dd HH:mm:ss.SSS");

Using a different time zone

To use a different time zone check the advanced box and select your time zone from the helper icon. It gives you:

IDate date1 = new IDate("yyyy-MM-dd HH:mm:ss", "", "", TimeZone.getTimeZone("Europe/Stockholm"));

Load different date

When you need to load a custom date from a String check the advanced box, select your timezone using the helper icon and in the Date from String select the String that holds the date you would like to read, and in the Format of the string field you specify what format this date has. This will give you:

IDate date1 = new IDate("yyyy-MM-dd HH:mm:ss", "880214", "yyMMdd", TimeZone.getTimeZone("Europe/Stockholm"));

Remember to specify the Date of the string exactly as the date you're reading. In our example above we have the date 1988-02-14 n a short form of yyMMdd.