2011-12-22 90 views
0

我有一个数组,其中包含HH:mm:ss格式的时间。在iPad中计算纪元时间

我想这转化为划时代的时间。要将特定时间转换为时间,应该传递日期和时间。

我想通过今天的日期从阵列时间一起。

例如09:15:30(日期22/12/2011),它是一个字符串,应该被转换为1324525530000(对应元值)

我应该如何转换此??

任何帮助表示赞赏。

回答

4

乘以这个秒也许你可以得到一个想法在看这个片段:

NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] initWithSafeDateFormat:@"dd/MM/yyyy HH:mm:ss"]; 
NSDate *date = [dateFormatter dateFromString:dateString]; 
NSTimeInterval epoch = [date timeIntervalSince1970]; 

反正你可以去看看到参考文档中的NSDateFormatter和NSDate。

2

这看起来像以毫秒为单位划时代的时间 - 因为据我所知,这应该是在几秒钟。

您可以使用NSDateFormatter解析字符串,并将其转换为NSDate。那么这个日期可以返回自1970年以来如果你真的需要它,只需1000

+0

[是,我可以(http://www.google.com/search?q=nsdateformatter+tutorial) – 2011-12-22 10:47:50

+0

你要通过的日期时间格式为它知道什么解析。 – 2011-12-22 10:51:59

+0

(未经测试)'NSDateFormatter * df = [NSDateFormatter new]; [dateFormatter setDateFormat:@“theformat”]; NSDate * convertedDate = [df dateFromString:@“22/12/2011 09:15:30”]; [df release];' - 您可能想要查看该格式的[日期格式的此页](http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns)。 “dd/MM/YYYY HH:mm:ss”可能适合你。 – 2011-12-22 12:07:57