How can I generate convenient date ranges based on a given NSDate?

后端 未结 2 1803
有刺的猬
有刺的猬 2021-02-01 11:14

I\'m creating a report generator in Cocoa, and I need to produce convenient date ranges such as \"Today\", \"This Week\", \"This Month\", \"This Year\", etc.

Is there a

2条回答
  •  迷失自我
    2021-02-01 11:57

    Well since timeInterval is in seconds, just do the math to figure out how many seconds are in a day:

    60 seconds * 60 minutes * 24 hours = 1 day.

    Then in your rangeForDayContainingDate method you could extract date components, get the current day, create a new date based on the day with hours and minutes set to 0:00, and the create the end date adding the time interval as calculated above.

提交回复
热议问题