Convert float to NSDate

I want to convert float to NSDate

I converted NSDate to float using this:

// Turn the date into Integers 
NSCalendar *calendar= [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];  
NSCalendarUnit unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;  
NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:nsdate_wakeTime];  
NSInteger hour = [dateComponents hour];  
NSInteger min = [dateComponents minute];  

//Convert the time in 24:60 to x.x format.
float myTime = hour + min/60; 

after some math material that I do in the mytime variable, I get a bunch of other times in the same float format.

How to turn float into NSDate?

Thanks!

+3
source share
1 answer

If you convert the time that you calculated in seconds (like mytime * 60), you can use dateWithTimeIntervalSinceReferenceDate:to go back to NSDate. From the math you do, it looks like the indicated date here will be 00:00 during the day in question. As Jason said, probably the best way to do what you are trying to accomplish.

, myTime 60.0, ; 60 60, 0.

+2

Source: https://habr.com/ru/post/1708012/


All Articles