I have 2 times values in NSString either in 12 hour format(10-09 PM) or 24 hour format (18-12). How to calculate time difference between two? (two dates will be either in 12 hour or 24 hour format, not mixed format)
NSDateFormatter *df=[[NSDateFormatter alloc] init];
// Set the date format according to your needs
[df setDateFormat:@"MM/dd/YYYY hh:mm a"]; //for 12 hour format
//[df setDateFormat:@"MM/dd/YYYY HH:mm "] // for 24 hour format
NSDate *date1 = [df dateFromString:firstDateString];
NSDate *date2 = [df dateFromString:secondDatestring];
NSLog(@"%@f is the time difference",[date2 timeIntervalSinceDate:date1]);
[df release];
hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With