NSString表示的时间转为time_t

 1 time_t convertTimeStamp(NSString *stringTime)
2 {
3 time_t createdAt;
4 struct tm created;
5 time_t now;
6 time(&now);
7
8 if (stringTime) {
9 if (strptime([stringTime UTF8String], "%a %b %d %H:%M:%S %z %Y", &created) == NULL) {
10 strptime([stringTime UTF8String], "%a, %d %b %Y %H:%M:%S %z", &created);
11 }
12 createdAt = mktime(&created);
13 }
14 return createdAt;
15 }
posted @ 2012-02-25 19:40  woainilsr  阅读(535)  评论(0编辑  收藏  举报