iOS get 0 points on the day

Source: Internet
Author: User

Recently a company A project has a pit, show no 0 points of data, modify the starting time of the day before 23 points 59 minutes 59 seconds can be displayed.

Check out the 0-point code for the day, and the results are basically consistent with those found online, as shown below (using category on NSDate):

1-(NSDate *) Zeroofdate2 {3Nscalendar *calendar =[Nscalendar Currentcalendar];4Nsdatecomponents *components =[Calendar Components:nsuintegermax fromdate:self];5Components.hour =0;6Components.minute =0;7Components.second =0;8     return[Calendar datefromcomponents:components];9}

Plus log found that the return of the date Nstimeinterval value after the decimal point is not 0, because nanosecond is not 0, and iOS can not use Components.nanosecond = 0, so use the following methods to solve:

1-(NSDate *) Zeroofdate2 {3Nscalendar *calendar =[Nscalendar Currentcalendar];4Nsdatecomponents *components =[Calendar Components:nsuintegermax fromdate:self];5Components.hour =0;6Components.minute =0;7Components.second =0;8     9     //Components.nanosecond = 0 Not available in IOSTenNstimeinterval ts = (Double)(int) [[Calendar datefromcomponents:components] timeIntervalSince1970]; One     return[NSDate datewithtimeintervalsince1970:ts]; A}

Make a mark in case the pit is later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.