我在代码中使用时间时遇到了一些麻烦:
txtDauer = new JFormattedTextField();
txtDauer.setFormatterFactory(new DefaultFormatterFactory(
new DateFormatter(DateFormat.getTimeInstance())));
当我对上面的 FormattedTextfield 使用 setValue(0) 时,文本字段显示 01:00:00 而不是 00:00:00。
使用此方法的另一行代码也出现同样的问题:
public static String convertLongToString(Long time) {
String strtime = new SimpleDateFormat("HH:mm:ss").format(time);
return strtime;
}
使用此方法与“0”,它返回 strtime =“01:00:00”。
问题是时区,您的默认计算机的时区是 GMT +1。
解决方案是将 GMT 设置为 +0:
DateFormat df = new SimpleDateFormat("HH:mm:ss");
df.setTimeZone(TimeZone.getTimeZone("GMT"));
运行并预览。 http://ideone.com/U3Gmk
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)