NSDate 为正确设置的 NSDateFormatter 返回 nil [英] NSDate returning nil for the NSDateFormatter set correctly

查看:41
本文介绍了NSDate 为正确设置的 NSDateFormatter 返回 nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在获取 NSString 格式的日期,如下所述.

I am getting the date in NSString format as mentioned below.

输入:日期字符串 = 30/04/2013 04:49 PM

我正在应用下面提到的 NSDateformatter 格式来将此 NSString 转换为 NSDate .

I am applying the format for NSDateformatter as mentioned below to convert this NSString to NSDate .

格式:dateFormat= dd/MM/yyyy hh:mm a

我仍然将日期转换为 Nil.请帮助,因为我不理解这个问题.这是我的代码片段,用于解释我在实用程序函数中所做的事情.

I still get the date conversion to Nil. Please help as I am not understanding this issue.Here is my code snippet to explain what i am doing in the utility function.

  NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  [dateFormatter setDateFormat:dateFormat];
  NSDate *date = [dateFormatter dateFromString:dateString];
  return date;

推荐答案

Try This....

Try This....

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/MM/yyyy hh:mm a"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
NSDate *date = [dateFormatter dateFromString:@"30/04/2013 04:49 PM"];
NSLog(@"%@",date);

这篇关于NSDate 为正确设置的 NSDateFormatter 返回 nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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