How to determine if an NSDate is today?

前端 未结 20 2012
礼貌的吻别
礼貌的吻别 2020-11-28 18:20

How to check if an NSDate belongs to today?

I used to check it using first 10 characters from [aDate description]. [[aDate descriptio

20条回答
  •  遥遥无期
    2020-11-28 18:47

    You could also check the time interval between the date you have, and the current date:

    [myDate timeIntervalSinceNow]
    

    This will give you the time interval, in seconds, between myDate and the current date/time.

    Link.

    Edit: Note to everyone: I'm well aware that [myDate timeIntervalSinceNow] does not unambiguously determine whether myDate is today.

    I am leaving this answer as is so that if someone is looking for something similar and [myDate timeIntervalSinceNow] is useful, they may find it here.

提交回复
热议问题