How to get NSDate for 00:00 on the day of [NSDate date]?

前端 未结 3 1882
攒了一身酷
攒了一身酷 2020-12-15 10:04

I need to get an NSDate object for 00:00(beginning of the day) from [NSDate date], let\'s say if currently it is 11:30am(returned by [NSDate date]), on 01/06/2012, now I nee

3条回答
  •  孤街浪徒
    2020-12-15 10:15

    What you doing is correct, but when you NSLog morningStart the date will be displayed in GMT time zone

    If you wanna make sure that the date is correct, convert it to NSString

     NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
     [formatter setDateFormat:@"yyyy-MMM-dd HH:mm:ss"];
     NSString *strFromDate = [formatter stringFromDate:morningStart]; // this will return 2012-Jun-21 00:00:00
    

提交回复
热议问题