Hi,
I have a JSpinner formated to use a date model. The format of the text displayed includes the time zone. The time zone displayed is my local time zone and I would like it to be a different time zone (Etc/UTC). I have tried setting the time zone of date the spinner is intialized with as well as the SimpleDateFormat string passed into the editor, but the spinner still displays the local time zone. I have been searching online and in the forums and while I've found lots of issues with using the date model spinner, I haven't found this particular issue. Any help is greatly appreciated!!
Here is my code:
// Save off the current date and time
GregorianCalendar now = new GregorianCalendar();
// Set the timezone to be UTC
now.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
// Create a date/time spinner with a default value of the current
// date and time, no upper or lower bounds, and can be
// incremented by the minute.
JSpinner myTimeSpinner = new JSpinner(
new SpinnerDateModel(now, null, null, Calendar.MINUTE)
{
// This empty method is needed for the MINUTE increment
// to work; otherwise it increments by the first field
// in the display
public void setCalendarField(int field){}
});
// Define a time format to be used
SimpleDateFormat myTimeFormat =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
// Set the time zone on the format
myTimeFormat.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
// Set the editor to use the defined time format
myTimeSpinner.setEditor(
new JSpinner.DateEditor(myTimeSpinner,
myTimeFormat.toPattern()));
Thanks again!
Naomi