Android java.util.Calendar - Time Difference

前端 未结 3 507
再見小時候
再見小時候 2021-01-22 09:07

I want to make calendar view in order to support touch interaction. So I\'d like to build new custom calendar view. I tried to make mapping function between view offset and rea

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-22 09:44

    This statement confuses me:

    /* I expect mBaseDate == mAnotherDate.
     * but it was different.
     */
    

    Are you actually trying to check for equality by doing the comparison: if (mBaseDate == mAnotherDate) { System.out.println("They are the same"); }

    If so, your issue is that you are misunderstanding how the "==" operator works in Java. It compares references, rather than comparing the underlying object data, and since these are different objects (with the same values) that will always be false. For a lot more details, see the Java Notes on comparison operators.

    Also, these lines look really suspicious to me:

    /* We SHOULD call to update mDate internal data structure. 
    * Java is really strange for this thing
    **/
    mDate.getTimeInMillis();
    

    I would really be surprised if Android had a bug requiring you to do this, but I guess anything is possible. What kind of problems do you have without this call?

提交回复
热议问题