Objective-C time lapse

In C #, if I wanted to parse a string into a date and time, I would do something similar to the following:

String input = "08:00";
DateTime time;
if (!DateTime.TryParse(input, out time))
{
    // invalid input
    return;
}

TimeSpan timeSpan = new TimeSpan(time.Hour, time.Minute, time.Second);

My Google-Fu was less desirable in finding a way to convert it to Objective-C.

Any suggestions?

+3
source share
1 answer

Cocoa's date and time programming guide is likely to be helpful in finding the approach that best suits your needs. I would argue that NSDateComponents will be of particular interest - you can get an instance of this class from -[NSCalendar components:fromDate:].

, : NSDateFormatter, -dateFromString: -stringFromDate: NSString NSDate. -setDateFormat: , . NSDate, -timeIntervalSince... NSTimeInterval, , .

+7

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


All Articles