有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将系统时间与我获取它的时间进行比较

我收到错误:-
仪器状态:stack=安卓。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) 个答案

  1. # 1 楼答案

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