我从特定时间开始计时表时遇到问题。我希望我的计时器从一个 Date 对象开始:
Date d = new Date(); //now, just for example
chronometer.setBase(d.getTime()); //long value of d
Log.d("Date: " , "d.getTime() time is [" + d.getTime() +"]");
Log.d("Chron: " , "chronometer.getBase() is [" + chronometer.getBase() +"]");
//let's print out elapsedRealtime from official sample
Log.d("Chron: " , "SystemClock.elapsedRealtime() is [" + SystemClock.elapsedRealtime() +"]");
输出:
06-02 13:35:23.025: D/Date:(928): d.getTime() time is [1338644123032]
06-02 13:35:23.037: D/Chron:(928): chronometer.getBase() is [1338644123032]
06-02 13:35:23.037: D/Chron:(928): SystemClock.elapsedRealtime() is [11624388]
实际上,为什么这么长的时间值不同(11624388 和 1338644123032)?
当我从底座启动我的计时器时
chronometer.setBase(SystemClock.elapsedRealtime());
- 它总是工作正常(“00:00”和上升)
但是当我尝试从过去的日期(昨天)设置日期时:
chronometer.setBase(yesterday.getTime());
- 它显示“00:0(”并每秒将最新的字符更改为“)”、“*”、“/”等
您能否建议我如何将计时器底座设置为 Date 对象?