经过进一步的调查,我找到了正确的答案。正如SkipHead所提到的,我从我的应用程序中得到的时间戳正在被调整到用户的时区。因此,如果用户输入6:12 PM(EST),我将得到2:12 PM(格林尼治标准时间)。我需要的是一种撤销转换的方法,这样用户输入的时间就是发送到WebServer请求的时间。我是如何做到这一点的:
// Get TimeZone of user
TimeZone currentTimeZone = sc_.getTimeZone();
Calendar currentDt = new GregorianCalendar(currentTimeZone, EN_US_LOCALE);
// Get the Offset from GMT taking DST into account
int gmtOffset = currentTimeZone.getOffset(
currentDt.get(Calendar.ERA),
currentDt.get(Calendar.YEAR),
currentDt.get(Calendar.MONTH),
currentDt.get(Calendar.DAY_OF_MONTH),
currentDt.get(Calendar.DAY_OF_WEEK),
currentDt.get(Calendar.MILLISECOND));
// convert to hours
gmtOffset = gmtOffset / (60*60*1000);
System.out.println("Current User's TimeZone: " + currentTimeZone.getID());
System.out.println("Current Offset from GMT (in hrs):" + gmtOffset);
// Get TS from User Input
Timestamp issuedDate = (Timestamp) getACPValue(inputs_, "issuedDate");
System.out.println("TS from ACP: " + issuedDate);
// Set TS into Calendar
Calendar issueDate = convertTimestampToJavaCalendar(issuedDate);
// Adjust for GMT (note the offset negation)
issueDate.add(Calendar.HOUR_OF_DAY, -gmtOffset);
System.out.println("Calendar Date converted from TS using GMT and US_EN Locale: "
+ DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)
.format(issueDate.getTime()));
代码的输出是:(用户输入了5/1/2008 6:12 pm(EST)
当前用户的时区:EST
来自格林尼治时间的电流偏移(小时):-4(通常为-5,DST调整除外)
机场核心计划TS:2008-05-01 14:12:00.0
使用GMT和US_EN地区从TS转换的日历日期:5/1/08 6:12 PM(格林尼治时间)