将特定格式转换为 NSDate [英] To convert a particular format to NSDate

查看:69
本文介绍了将特定格式转换为 NSDate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 Web 服务获取日期组件为 @"2014-01-08T00:00:00.000Z".我需要将其转换为仅提供年、月和日期的日期.请帮忙

I am getting a date component from web service as @"2014-01-08T00:00:00.000Z". I need to convert it into a date only providing me with year , month and date. Please help

推荐答案

使用此代码获取当前日期

Use this code to get the Current Date

NSDateFormatter *dateFor=[[NSDateFormatter alloc]init];
NSString *currentDateString = @"2014-01-08T21:21:22.737+05:30";

[dateFor setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZ"];        
NSDate *currentDate = [dateFor dateFromString:currentDateString];

NSLog(@"CurrentDate:%@", currentDate);

这篇关于将特定格式转换为 NSDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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