GWT - 显示的日期递减一天



我使用的服务器在澳大利亚墨尔本。我有来自澳大利亚珀斯的报告,显示的日期减少了一天(即 2003-10-31 显示为 2003-10-30)。在我的读数中,我发现我需要设置时区。他们说不要使用两个/三个字母的时区使用完整的时区。但是,我找不到澳大利亚墨尔本的完整时区。任何人都可以帮忙吗?

我想出的代码是:

//Display the DOB
DateTimeFormat fmt = DateTimeFormat.getFormat("yyyy-MM-dd australiaMelbourne");
String stringDOB = fmt.format(ythMmbrSectDtls.getDob());
Label dateLblDOB = new Label(stringDOB);
dateLblDOB.setStyleName("gwt-Label-Login");
dateLblDOB.setWidth("100px");
flexTable.setWidget(row, 3, dateLblDOB);

代码应该是(在服务器端):

 while (result.next()) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(result.getDate("dob"));
                TimeZone timeZone = TimeZone.getDefault();
                calendar.setTimeZone(timeZone);
                java.sql.Date javaSqlDateDOB = new java.sql.Date(calendar.getTime().getTime());
                VenturerSectDtls venturerSectDtls = new VenturerSectDtls(
                        result.getString("cdID"), 
                        null, 
                        result.getString("surname"), 
                        result.getString("firstName"),
                        javaSqlDateDOB,
                        //result.getDate("dob"),

完整的时区格式是Continent/City所以在你的例子中Australia/Melbourne.

有关更多信息,请参阅:http://tutorials.jenkov.com/java-date-time/java-util-timezone.html

使用 SimpleDateFormat 而不是 DateTimeFormat

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ENGLISH);

请在此处查看简单日期格式的文档

爪哇 6 : http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

爪哇 7 : http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

最新更新