-5

Web サービスからこの形式の文字列を取得しています。 13:44。どうすればこれを達成できますか?

4

2 に答える 2

1

これを使って :

NSString *str = @"Fri, 19 Jul 2013 07:13:44 GMT";
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"EE, dd MMM yyyy HH:mm:ss z"];
NSDate *date = [df dateFromString:str];
NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[df setTimeZone:sourceTimeZone];

NSDate *dateFromString = [df dateFromString:str];
[df setDateFormat:@"HH:mm:ss"];

// This is the time you need
NSString *timeIs = [df stringFromDate:date];
于 2013-07-19T08:21:36.180 に答える
1

NSString *pubDateString = [NSString stringWithFormat:@"Fri, 19 Jul 2013 07:13:44 GMT"];

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss zzz"];

NSDate *pubDate = [df dateFromString:pubDateString];

[df setDateFormat:@"HH:mm:ss"];
[df setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];

NSLog(@"%@",[df stringFromDate:pubDate]);

出力:07:13:44

Apple の日付フォーマット ガイド: http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html

于 2013-07-19T08:34:28.230 に答える