Android的位置的getTime()总是返回大不同时间 [英] Android location getTime() always returns big different time

查看:2515
本文介绍了Android的位置的getTime()总是返回大不同时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到的位置使用位置管理器regulary根据设置,在测试的情况下2分钟,并尝试使用location.geTime()方法。我不使用LocationManager.getLastKnownLocation()。文件说,这是UTC时间,我将它转换为本地时间如下图所示:

I am getting location using Location Manager regulary depending on the setting, 2minutes in testing case and trying to use location.geTime() method. I am not using LocationManager.getLastKnownLocation(). Document says it is UTC time and I converted it to local time like below:

Date d = new Date(location.getTime());
SimpleDateFormat sdf = new SimpleDateFormat("yyMMddkkmmss';
sdf.setTimeZone(TimeZone.getTimneZone("UTC");
sdf.format(d);

不过,我得到不同的日期从我的期望。当前时间我写约为130516155000(2013年5月16号15点50分00秒),但我得到040015130515。 而且我删除了时区,并设置时区GMT,以及和日期固定但时间是完全不同的。在实际设备和仿真器是一样的。而且我已经检查了这两个时区设置,它们是正确的。 请告诉我,我缺少的是什么?

But I am getting different date from what I expect. Current time I am writing is about 130516155000(2013-05-16 15:50:00) but I am getting 040015130515. And I removed the timezone and set the time zone as 'GMT' as well and date fixed but time was quite different. In real device and emulator are same. And I already checked timezone setting in both and they are correct. Please tell me what I am missing?

感谢。

编辑:

我添加更多。

Log:
05-16 16:09:30.227: D/location.getTime()(1279): 1368590417000
05-16 16:09:30.237: D/NMEAGPRMCTime(1279): 040017
05-16 16:09:30.247: D/NMEAGPRMCDate(1279): 130515

code:

Code:

public static String NMEAGPRMCTime(Date d)
{
    SimpleDateFormat sdf = new SimpleDateFormat("kkmmss");
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    String result = sdf.format(d);
    Log.d("NMEAGPRMCTime", result);
    return result;
}


public static String NMEAGPRMCDate(Date d)
{
    SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    String result = sdf.format(d);
    Log.d("NMEAGPRMCDate", result);

    return result;
}

就是这样。这是code正是我使用的是什么。

That's it. This is the code exactly what I using.

推荐答案

但绝对没有错,这里的格式。

There's absolutely nothing wrong with the formatting here.

查看日志:

05-16 16:09:30.227: D/location.getTime()(1279): 1368590417000
05-16 16:09:30.237: D/NMEAGPRMCTime(1279): 040017
05-16 16:09:30.247: D/NMEAGPRMCDate(1279): 130515

使用 epochconverter 你可以看到,1368590417000的米利斯,因为时代值实际上是星期三,5月15日2013 4点00分十七秒UTC。所以040017一时间和130515日期是完全正确的。

Using epochconverter you can see that the "millis since epoch" value of 1368590417000 is actually Wed, 15 May 2013 04:00:17 UTC. So a time of 040017 and a date of 130515 is exactly right.

我怀疑你实际上是通过何种 <混淆code> Location.getTime() 那样 - 它返回的修复,而不是当前的时间的时间。因此,基本上,在四点00分17秒UTC得到该位置,而不管当前的日期/时间。

I suspect you're actually confused by what Location.getTime() does - it returns the time of the fix, not the current time. So basically, that location was obtained at 04:00:17 UTC, regardless of the current date/time.

这篇关于Android的位置的getTime()总是返回大不同时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆