[Solved] How to compare array of dates with greater than current date

i Resolved my issue by using stack overflow suggestions. and i am posting my answer it may helpful for others. extension Date { var startOfWeek: Date? { let gregorian = Calendar(identifier: .gregorian) guard let sunday = gregorian.date(from: gregorian.dateComponents([.yearForWeekOfYear, .weekOfYear], from: self)) else { return nil } return gregorian.date(byAdding: .day, value: 1, to: sunday) } var … Read more

[Solved] How do I convert a parameterised enum/ enum with associated values from Swift to Objective-C? [closed]

Let me explain your code for you: NSString *isoFormat = ISO8601DateFormatType; (assigns string ISO8601 to isoFormat) NSString *dateFormat = (isoFormat != nil) ? isoFormat : ISO8601DateFormatType; (isoFormat is never nil so the condition is always true. If it were false, we would again assign string ISO8601). NSDateFormatter *formatter = … (we get some formatter, it … Read more

[Solved] How to compare two time from NSDate. Returning nil for nsdate when doing comparision. #debug my code

There was a typo:[dateFormatter setDateFormat:@”HH:mm:ss”]; should be:[formatter setDateFormat:@”HH:mm:ss”]; To compare two dates use: NSDate *date1 = [NSDate date]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@”HH:mm:ss”]; NSDate *date2 = [formatter dateFromString:@”05:00:00″]; NSComparisonResult result = [date1 compare:date2]; if(result == NSOrderedDescending) { NSLog(@”date1 is later than date2″); } If you only want to compare the hours: NSCalendar … Read more

[Solved] Converting Date to proper format when the Value obtained from the Db is in format 2012-07-13 00:00:00.0 [duplicate]

Use this one NSString *dateStr=@”2012-07-13 00:00:00.0″; NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@”yyyy-MM-dd HH:mm:ss.S”]; NSDate *date = [df dateFromString: dateStr]; [df setDateFormat:@”MM/dd/yyyy”]; NSString *convertedString = [df stringFromDate:date]; NSLog(@”Your String : %@”,convertedString); Output: Your String : 07/13/2012 6 solved Converting Date to proper format when the Value obtained from the Db is in format 2012-07-13 … Read more

[Solved] how to I convert a string with format “YYYY/MM/DD” into NSDate type? [duplicate]

You can convert it to an NSDate using the NSDateFormatter. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@”yyyy/MM/dd”]; NSdate *date = [dateFormatter dateFromString:@”2012/03/17″]; Be aware that allocating an NSDateFormatter is a pretty heavy task so if you are parsing a lot of dates then allocate it once and keep it around 🙂 solved how to … Read more

[Solved] Calculate time interval to 0.00 of the next day according to GMT in swift or objective-c?

First create a Calendar for the UTC timezone. Second get the startOfDay using the UTC calendar. Third add one day to that date. Then you can useDatemethodtimeIntervalSince(_ Date)` to calculate the amount of seconds between those two dates: extension Calendar { static let iso8601UTC: Calendar = { var calendar = Calendar(identifier: .iso8601) calendar.timeZone = TimeZone(identifier: … Read more

[Solved] NSDateFormatter returning nil with dateFromString

NSString *trimmedDOB=@”1992-11-15″; NSDateFormatter *format = [[NSDateFormatter alloc] init]; //Set your input format [format setDateFormat:@”yyyy-MM-dd”]; //Parse date from input format NSDate *dateOfBirth = [format dateFromString:trimmedDOB]; //Set your output format [format setDateFormat:@”MM-dd-yyyy”]; //Output date in output format NSLog(@”DATE IS %@”,[format stringFromDate:dateOfBirth]); 0 solved NSDateFormatter returning nil with dateFromString

[Solved] Getting the first date from what a user has selected

First you need to create an enumeration for the weekdays: extension Date { enum Weekday: Int { case sunday = 1, monday, tuesday, wednesday, thursday, friday, saturday } } Second create an extension to return the next weekday desired: extension Date { var weekday: Int { return Calendar.current.component(.weekday, from: self) } func following(_ weekday: Weekday) … Read more