objective c - Truncate NSDate (Zero-out time) -


i want generate new nsdate 0 hours, 0 minutes, , 0 seconds time. source date can random nsdate.

is there way achieve this? documentation did not me this.


example

have: 2010-10-30 10:14:13 gmt

want: 2010-10-30 00:00:00 gmt

unsigned int flags = nscalendarunityear | nscalendarunitmonth | nscalendarunitday; nscalendar* calendar = [nscalendar currentcalendar]; nsdatecomponents* components = [calendar components:flags fromdate:date]; nsdate* dateonly = [calendar datefromcomponents:components]; 

date date want remove time from.

this separates date , time , creates new date default time (00:00:00).

edit

to take time zone account:

nsdate* dateonly = [[calendar datefromcomponents:components] datebyaddingtimeinterval:[[nstimezone localtimezone]secondsfromgmt]]; 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -