[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 *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] 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] date not showing in correct manner

Try to change like this: In ViewDidload: firstdate = [[NSCalendar currentCalendar] dateByAddingUnit:NSCalendarUnitDay value:-6 toDate:[NSDate date] options:nil]; // And below method -(void)dateChange { NSArray *labelArray = @[flabel, slabel, tlabel, folabel, fivlabel,sixlabel,sevenlabel]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSCalendar *calendar = [NSCalendar currentCalendar]; dateFormatter.dateFormat = @”ddMMM”; for (NSInteger i = 0; i < 7; ++i) { NSDate … Read more

[Solved] 2017-08-16 05:08:54 Convert String to in Date “17-Aug 13 : 30” using swift 3

The input is yyyy-MM-dd hh:mm:ss and the output is dd-MMM HH:mm.So do like let outFormatter = DateFormatter() // set the input format outFormatter.dateFormat = “yyyy-MM-dd hh:mm:ss” // convert your string to date let date = outFormatter.date(from: “2017-08-16 05:08:54”)! // set the output format outFormatter.dateFormat = “dd-MMM HH : mm” // convert your date to expected … Read more

[Solved] Using NSDateFormatter in objective-C [duplicate]

First, your date format is wrong — the second line should be [dateFormatter setDateFormat:@”yyyy-MM-dd’T’HH:mm:ss.000Z”]; — that is, you need the ss. after the mm: but before the 000Z. This will give you the correct NSDate. Next, you need to create a new date formatter with the format @”dd.M.yyyy” (or @”d.M.yyyy” if you want to remove … Read more