Truncate NSDate (Zero-out time)

前端 未结 6 896
孤街浪徒
孤街浪徒 2020-12-02 19:02

I want to generate a new NSDate with 0 hours, 0 minutes, and 0 seconds for time. The source date can be any r

6条回答
  •  佛祖请我去吃肉
    2020-12-02 19:21

    I would use the description method to get the given date as a string, then modify the string and create your new date with initWithString.

    initWithString: Returns an NSDate object initialized with a date and time value specified by a given string in the international string representation format.

    • (id)initWithString:(NSString *)description Parameters description A string that specifies a date and time value in the international string representation format—YYYY-MM-DD HH:MM:SS ±HHMM, where ±HHMM is a time zone offset in hours and minutes from GMT (for example, “2001-03-24 10:45:32 +0600”). You must specify all fields of the format string, including the time zone offset, which must have a plus or minus sign prefix. Return Value An NSDate object initialized with a date and time value specified by aString.

提交回复
热议问题