currentDateTime = [NSDate date];
dateFormatter = [[NSDateFormatter alloc]init] ;
[dateFormatter setDateFormat:@"yyyy-mm-dd hh:mm"]; // 1999-12-12 14:50
dateInString = [dateFormatter stringFromDate:currentDateTime];
metTime.text=dateInString;
NSLog(@"date %@", dateInString);
我尝试将当前时间作为字符串参数发送到 Web 服务方法。我可以看到它但是当传递 dateInString 时我得到一个错误,例如
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.FormatException: String was not recognized as a valid DateTime. at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.Convert.ToDateTime(String value) at MrkService.MrkService.AddMeetingInfo(String phoId, Int32 metId, Int32 cusId, Int32 metTyp, Int32 metRes, String desc, String contc, String endTime) --- End of inner exception stack trace ---
有没有人知道这个问题(网络服务方法参数是字符串不是日期)
最佳答案
这个模式在我看来很不对:
yyyy-mm-dd hh:mm
看看你是如何使用“mm”两次的?而“hh”通常表示 12 小时制......我怀疑你想要
yyyy-MM-dd HH:mm
其中 MM 表示月份(不是分钟),HH 表示 24 小时制。这是假设 iOS 日期和时间模式与其他平台的工作方式类似......
事实上,您可能需要对模式进行进一步的更改 - 例如包括秒,可能还有一个 T,例如
yyyy-MM-ddTHH:mm:ss
关于objective-c - objective-c 中的日期时间问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7537753/