The JVM apparently does not detect system changes to the timezone in NT 4.0. To
see this, run the test case below and, while the application is running, change the system timezone (In Control Panel, select Date/Time | Timezone). Then click
the application's "Show TimeZone" button. The timezone displayed will be the original timezone.
This occurs in 1.1.7B and 1.2.
========================================================
========================================================
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class TestTimeZone extends JFrame {
JTextArea ta = new JTextArea(15, 50);
JTextField tf = new JTextField(10);
JButton showTimeButton = new JButton("Show Time");
JButton setButton = new JButton("Set Time Zone");
JPanel buttonPanel = new JPanel(new FlowLayout());
JPanel fieldsPanel = new JPanel(new GridBagLayout());
JButton showZoneButton = new JButton("Show TimeZone");
public TestTimeZone() {
String[] ids = TimeZone.getAvailableIDs();
System.out.println(ids.length + " time zones");
for (int i = 0; i < ids.length; i++)
System.out.print(ids[i] + " ");
System.out.println("\n\n");
Container c = getContentPane();
c.setLayout(new BorderLayout());
buttonPanel.add(showTimeButton);
buttonPanel.add(setButton);
buttonPanel.add(showZoneButton);
GridBagConstraints gbc = new GridBagConstraints();
gbc.weighty = 0;
((GridBagLayout)fieldsPanel.getLayout()).setConstraints(tf, gbc);
fieldsPanel.add(tf);
gbc.gridy = 1;
gbc.weighty = 1;
JScrollPane taScroll = new JScrollPane(ta);
((GridBagLayout)fieldsPanel.getLayout()).setConstraints(taScroll, gbc);
fieldsPanel.add(taScroll);
c.add(BorderLayout.CENTER, fieldsPanel);
c.add(BorderLayout.SOUTH, buttonPanel);
showZoneButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ta.append(" TimeZone.getID says: " + TimeZone.getDefault().getID() + "\n");
ta.append(" Calendar.getInstance().get(Calendar.ZONE_OFFSET) says: " + Calendar.getInstance().get(Calendar.ZONE_OFFSET) + "\n");
ta.append(" Calendar.getInstance().get(Calendar.DST_OFFSET) says: " + Calendar.getInstance().get(Calendar.DST_OFFSET) + "\n");
}});
showTimeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ta.append(new Date().toString() + "\n");
}});
setButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("TimeZone before = " + TimeZone.getDefault());
TimeZone.setDefault(TimeZone.getTimeZone(tf.getText()));
System.out.println("TimeZone after = " + TimeZone.getDefault());
}});
pack();
setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}});
//setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
Date date = new Date();
public final static void main(String[] a) {
new TestTimeZone();
}
}