0

我已经记录了发布并从服务器获得响应所花费的时间。但时间似乎比我的系统时钟早 4 小时。

我使用的代码是:

String posttime = java.text.DateFormat.getTimeInstance().format(Calendar.getInstance().getTime());
Log.i("Time at which HTTP POST was sent",""+posttime );

日志中的输出是:

发送 HTTP POST 的时间 (323):晚上 8:24:53,而不是下午 4:24:54。

任何输入将不胜感激。

4

1 回答 1

2

The time is in UTC, you need to change the TimeZone to your local timezone

for example:

Calendar calendar = Calendar.getInstance();       
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss z");
sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
System.out.println(sdf.format(calendar.getTime()));
于 2013-08-08T20:35:09.663 回答