将NSDate转换为Sql Server Datetime格式

编程入门 行业动态 更新时间:2024-10-26 07:24:11
本文介绍了将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格式

本文发布于:2023-11-04 12:11:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557905.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   格式   NSDate   Sql   Datetime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!