I have two user selected dates: startDate and endDate. They are NSDate instances and I have to send them as parameters as NSNumber
s. How can I convert them to NSNumber with seconds?
How to send NSDate with a certain date format as NSNumber? i.e convert NSDate to NSDate with another format?
440 Views Asked by AbdulAziz Rustam Ogli At
3
There are 3 best solutions below
8

Use below code :
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
// set format however you want
[formatter setDateFormat:@"ddMMyyyy"];
NSDate *date = [NSDate date];
NSString *string = [formatter stringFromDate:date];
NSNumber *num1 = @([string intValue]);
NSLog(@"%@",num1);
0

If you mean a timestamp format NSDate *date = [NSDate date]; NSTimeInterval ti = [date timeIntervalSince1970]; How to convert NSDate into Unix timestamp in Objective C/iPhone?
Thanks,
1) First, get the date in
MM/dd/yyyy
format:2) get string date and remove '/' from it:
3) Use
NSNumberFormatter
from convertingNSString
toNSNumber
:Hope, this is what you want!