将字符串转换为NSDate [英] convert string into NSDate

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

问题描述

我有一个"DateTimeArray",该数组包含

i have a "DateTimeArray" this array contain

DateTimeArray[index 0] = 20.05.2011 12:12:50    
DateTimeArray[index 1]=  20.05.2011 12:13:20   
DateTimeArray[index 2]=  20.05.2011 12:20:10  

所有值都在字符串中,我想将此字符串转换为NSDate,只希望访问时间而不是日期
然后此时间值将存储在数组中,并且此新数组将用于绘制折线图

all the value are in string,and i want to convert this string into NSDate and only want to access time not date
and then this time values will be stored in array and this newly array will be used for drawing line chart

我希望有人知道这个问题

i hope some one know this issue

非常感谢

推荐答案

代码如下,

for(int index=0;index<[DateTimeArray count];index++)
{
   NSDateFormatter *df = [[NSDateFormatter alloc] init];
   [df setDateFormat:@"HH:mm:ss"];
   NSString *timeString=[[[DateTimeArray objectAtIndex:index]componentsSeparatedByString:@" "]objectAtIndex:1];
   NSDate *time=[df dateFromString:timeString];
   [timeArray addObject:time];
   [df release];
}

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

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