【问题标题】:day month and year time stamps from gps wrong来自gps的日月和年时间戳错误
【发布时间】:2015-02-16 11:01:12
【问题描述】:

我正在尝试从 GPS 获取时间戳。

我正在使用 onLocationChanged 方法和 Date 类,如下所示:

    public void onLocationChanged(Location location) {
        Date date = new Date(location.getTime());
        Log.d("TIME","day "+Calendar.get);
        Log.d("TIME","month "+date.getMonth());
        Log.d("TIME","year "+date.getYear());
        Log.d("TIME","hour "+date.getHours());
        Log.d("TIME","minutes "+date.getMinutes());
        Log.d("TIME","seconds "+date.getSeconds());
    }

现在我知道这些方法已被弃用,但它仍然可以给我准确的结果,对吧?

分钟、秒和小时都可以,但是:

天值为 1。

月份值为 1。

年份值为 115 。

我如何知道问题出在我从某个位置到达的时间上,还是日期类搞砸了?

【问题讨论】:

    标签: android time gps


    【解决方案1】:

    我认为年份值是 115,因为 2015 年是 1900 年之后的 115 年。 其他值可能有一些类似的解释。

    使用 SimpleDateFormater 格式化时间。

    SimpleDateFormat 格式 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String strTime = format.format(loc.getTime());

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-18
      • 1970-01-01
      • 2013-07-26
      • 1970-01-01
      • 2019-03-13
      • 2012-03-17
      • 1970-01-01
      • 2012-07-06
      相关资源
      最近更新 更多