3

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]; 
Sarah
  • 1,595
  • 3
  • 25
  • 34

3 Answers3

4
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.

Julian
  • 8,808
  • 8
  • 51
  • 90
3

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 .

Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76
0
NSDATE *date;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"ddMMyyyy"];
NSString *textDate = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:date]];
[dateFormatter release];
clement
  • 4,204
  • 10
  • 65
  • 133