Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java DateUtils getRelativeTimeSpanString不是';t返回时间单位为“;“X秒前”;_Java_Android_Android Dateutils - Fatal编程技术网

Java DateUtils getRelativeTimeSpanString不是';t返回时间单位为“;“X秒前”;

Java DateUtils getRelativeTimeSpanString不是';t返回时间单位为“;“X秒前”;,java,android,android-dateutils,Java,Android,Android Dateutils,我正在使用getRelativeTimeSpanString(…)将时间恢复到X秒前X小时前等 但是,当两次之间的差值很短(分或秒)时,它将在10小时内返回,而不是在X分钟前返回 以下是我如何使用它: Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH) .parse("2014-05-21 13:07:11"); Date currentDa

我正在使用getRelativeTimeSpanString(…)将时间恢复到
X秒前
X小时前

但是,当两次之间的差值很短(分或秒)时,它将在10小时内返回
,而不是在
X分钟前返回

以下是我如何使用它:

Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH)
                                .parse("2014-05-21 13:07:11");
Date currentDate = new Date();
CharSequence cs =  DateUtils.getRelativeTimeSpanString(date.getTime(), 
                                 currentDate.getTime(), DateUtils.SECOND_IN_MILLIS);

这意味着两者之间的差异是负的(因此将其解读为未来),您可以使用System.currentTimeMillis()而不是currentDate=new Date()dope…您是对的。我的模拟器上的时间不对。我将保留这个问题,以防其他人遇到:)这可能是一个时区问题。