本文介绍了将NSDate转换为Sql Server Datetime格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从iPhone应用程序调用一个 Web服务,该服务带有dateTime数据类型的参数.我想传递当前日期.我想知道我需要使用哪种日期格式.多谢您的协助,谢谢
I'm calling a 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
更新了答案以考虑时区.显然,您应该使用与原始日期相同的时区.
Updated answer to take timezone into account. Obviously you should use the same timezone used on the original date.
更多推荐
将NSDate转换为Sql Server Datetime格式
发布评论