Convert NSDate date and time format to Sql Server

I call the .net web service from an iPhone application that accepts a parameter with the dateTime data type. I want to pass the current date. I wanted to know which date format I need to use. I would be grateful for your help, Thank you

NSDate *now=[NSDate date]; 
+3
source share
3 answers

A more independent way would be to send time in the second instead of any format to your web server,

NSDate *now = [NSDate date]; 
NSTimeInterval inSecond = [now timeIntervalSince1970];

inSecond - type double, and let your web server calculate the time from the second message you sent.

+3
source
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 account for time zone. Obviously, you should use the same time zone that was used on the original date.

+3
source
NSDATE *date;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"ddMMyyyy"];
NSString *textDate = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:date]];
[dateFormatter release];
0

All Articles