kir*_*iri -3 objective-c nsdate nsdateformatter ios
在我的代码中,我从服务器获取一个字符串,值为"06-27-2014",然后我想转换为其他日期格式,但我得到的最终结果是非常不同的.这是我正在使用的代码.
NSString* dateVal = @"06-27-2014";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"mm-dd-yyyy"];
NSTimeZone *gmtZone = [NSTimeZone systemTimeZone];
[dateFormatter setTimeZone:gmtZone];
NSDate* aDate = [dateFormatter dateFromString:**dateVal**];
I am getting the aDate as **2014-01-26 18:36:00 +0000** here the month is completely changing to first month from 6th.
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateStyle:NSDateFormatterShortStyle];
NSDate *theDateSelected =aDate;
NSString *theDate = [dateFormat stringFromDate:theDateSelected];
Run Code Online (Sandbox Code Playgroud)
我得到的最后日期是2014年1月27日,这完全不同任何人都可以建议正确的日期格式.
您的日期格式错误,应该是MM月份.mm用了几分钟.
[dateFormatter setDateFormat:@"mm-dd-yyyy"];
Run Code Online (Sandbox Code Playgroud)
应该
[dateFormatter setDateFormat:@"MM-dd-yyyy"];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
59 次 |
| 最近记录: |