Skip to main content

Nebula CDateTime Widget(Date/Time Patterns and Formats)

There are two methods for setting which components of a date and/or a time you want your users to be able to select: 1. the easy way; or 2. the other way.

1. The Easy Way: Specify a Format, and let the JRE figure out the pattern

CDateTime.setFormat accepts a single bit-wise OR-ed int corresponding to the three types of java.util.DateFormat:

CDateTime.setFormat(CDT.DATE_XXX | CDT.TIME_YYY)
DateFormat.getDateTimeInstance(DateFormat.XXX, DateFormat.YYY) contains the following style constants:

DATE_LONGTIME_LONG (there is no corresponding DateFormat)

CDateTime cdt = new CDateTime(parent, CDT.BORDER | CDT.DROP_DOWN);

Note that date and time styles can also be used in the constructor:


2. The Other Way: Specify the exact pattern

Under the covers, CDateTime uses java.text.SimpleDateFormat to format its text and assist in the navigation of its fields. Because of this, any pattern that can be passed to SimpleDateFormat can be used (refer to the SimpleDateFormat Javadoc)

CDateTime cdt = new CDateTime(parent, CDT.BORDER | CDT.DROP_DOWN);
cdt.setPattern("'Meeting on' EEEE, MMMM d '@' h:mm 'in the'a");

Caveats and Special Considerations:

  • Due to the two parameter paradigm of SWT there is no way to pass a pattern into the constructor
  • Although inc/dec is supported, typing characters currently is not (ie: typing 'w' above will not select 'wednesday')
  • Secondary Calendar Fields are linked: changing the 'day of the week' field will change the 'date' field
  • There may not be a graphical compliment to every text field! (file an enhancement request)

Back to the top