使用时间格式化程序时我没有得到正确的时间 [英] I didn't get correct time when using time formatter

查看:58
本文介绍了使用时间格式化程序时我没有得到正确的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试从两个文本字段中获取日期和时间时,我得到的时间不正确.我的输入

When i tried to get date and time from two textfields, i got incorrect time. my input

date.text = may 20 2000    
time.text = 02:00 AM

but i got the time in nslog is :00:00:00 





NSString *datestring = self.date.text;
NSString *timestring = self.time.text;
NSString *combined = [NSString stringWithFormat:@"%@ %@", datestring, timestring];
NSLog(@"%@",combined);
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MMMM dd yyyy HH:mm:ss"];
NSDate *dates = [dateFormat dateFromString:combined];
self.create.hidden = YES;
NSLog(@"%@",dates);

任何帮助请?

推荐答案

您的格式化程序有误,应该是:

You have wrong formatter, it must be:

[dateFormat setDateFormat:@"MMMM dd yyyy hh:mm aa"];

这篇关于使用时间格式化程序时我没有得到正确的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆