I'm calling a .net web service from iPhone application that takes parameter with dateTime data type. I want to pass the Current date. I wanted to know which date format I need to use. I would appreciate your help, Thanks
NSDate *now=[NSDate date];
I'm calling a .net web service from iPhone application that takes parameter with dateTime data type. I want to pass the Current date. I wanted to know which date format I need to use. I would appreciate your help, Thanks
NSDate *now=[NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm:ss"];
[dateFormatter setTimeZone: [NSTimeZone timeZoneWithname:@"UTC"]];
NSString *sqlDate = [dateFormatter stringFromDate: date]; // date is your NSDate object
EDIT: Updated answer to take timezone into account. Obviously you should use the same timezone used on the original date.
The more independent way would be sending time in second instead of any format to your web server,
NSDate *now = [NSDate date];
NSTimeInterval inSecond = [now timeIntervalSince1970];
inSecond
is type of double , and let your web server to calculate the time from the second you send .
NSDATE *date;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"ddMMyyyy"];
NSString *textDate = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:date]];
[dateFormatter release];