[Solved] iOS After NSDateFormatter Date is nil [duplicate]

Use a dateFormat string of @”yyyy-MM-dd HH:mm:ss Z” instead. Your dateFormat does not match the format of the string you’re trying to convert. By the way, there’s no point in converting [NSDate date] to a string and back again. Just use [NSDate date] and be done with it: NSDate *compareDateNow = [NSDate date]; NSComparisonResult result … 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] How to change JSON string to date format in tableview

In which format do you want to convert. Try this one with your desired format if let dateString = JSONList[indexPath.row].createdDate{ let dateFormatter = DateFormatter() dateFormatter.locale = Locale(identifier: “en_US_POSIX”) dateFormatter.dateFormat = “yyyy-MM-dd HH:mm:ss” dateFormatter.timeZone = TimeZone(secondsFromGMT: 0) let date = dateFormatter.date(from: dateString) dateFormatter.dateFormat = “dd/MM/yyyy” let dateStr = dateFormatter.string(from:date!) cell.Date.text = dateStr } 0 solved How … 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 *[email protected]”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