[英]Convert NSDate to Sql Server Datetime format
我正在從iPhone應用程序調用一個帶有dateTime數據類型參數的.net Web服務。 我想通過當前日期。 我想知道我需要使用哪種日期格式。 非常感謝你的幫助,謝謝
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
編輯:更新了將時區考慮在內的答案。 顯然你應該使用原始日期使用的相同時區。
更獨立的方式是以秒為單位而不是任何格式向Web服務器發送時間,
NSDate *now = [NSDate date];
NSTimeInterval inSecond = [now timeIntervalSince1970];
inSecond
是double的類型,讓你的web服務器計算你發送的第二個時間。
NSDATE *date;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"ddMMyyyy"];
NSString *textDate = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:date]];
[dateFormatter release];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.