我试图从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。
我如何知道问题是从我到位的时间问题,还是Date类弄乱了?
答案 0 :(得分:0)
我认为年度值是115,因为2015年是1900年后的115年。 其他值可能有一些类似的解释。
使用SimpleDateFormater格式化时间。
SimpleDateFormat format = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
String strTime = format.format(loc.getTime());