【问题标题】:Compare the system time vs the time i fetch it比较系统时间和我获取它的时间
【发布时间】:2014-08-02 02:44:48
【问题描述】:

我收到错误:-
INSTRUMENTATION_STATUS: stack=android.util.TimeFormatException: 字符串太短 - 至少需要 8 个字符。

public void test() {

    TextView onDeviceTime = (TextView) mNextUIMainActivity.findViewById(R.id.timeOfDay);

    Time onSystem = new Time();
    onSystem.setToNow();
    Time onLauncherDisplay = new Time();
    onSystem.parse(onDeviceTime.getText().toString());
    if (onDeviceTime.equals(onSystem)) {
        System.out.println("Correct time!");
    }
}

【问题讨论】:

  • 而不是字符串比较尝试毫秒差异
  • @JigarJoshi natak na karis...sarkhi rite javab apavo hoi to aap

标签: java android time system


【解决方案1】:

您试图比较 Time 对象和 TextView 对象。听起来你真正想要的是if (onLauncherDisplay.equals(onSystem))

【讨论】:

  • 我应该将它与 onLauncherDisplay.equals(onSystem) 进行比较吗?
  • 是的,但您从未真正设置过onLauncherDisplay。您拥有它的方式就像将猫对象与房屋对象进行比较......这永远不会相等。
  • 同样的错误信息使用 if (onLauncherDisplay.equals(onSystem))
  • 听起来问题出在解析中。确保TextView 中有一个由parse api 指定的字符串。
  • 不,我给了你一个链接,它应该是什么样子,在运行 parse 命令之前检查 null 和/或空字符串。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-07-25
  • 1970-01-01
  • 2016-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-02
相关资源
最近更新 更多