比较系统时间与我获取它的时间

时间:2014-06-11 21:47:18

标签: java android time system

我收到错误: - 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!");
    }
}

1 个答案:

答案 0 :(得分:-1)

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