2

我得到一个NSString Sun Feb 24 2013 00:00:00 GMT+0530 (India Standard Time) 我想要的

将其转换为dd-mm-yy ios 。这就是我尝试的没有得到输出,因为我

通缉。将字符串转换为日期对象:

 NSString  *dateStr = @"Sun Feb 24 2013 00:00:00 GMT+0530 (India Standard Time) " ;
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"EE, d LLLL yyyy HH:mm:ss Z"];
    NSDate *date = [dateFormat dateFromString:dateStr];    
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-MM-dd hh:mm:ss a"];
    NSDate *myDate = [df dateFromString: stripped];

提前致谢。

4

6 回答 6

3
 NSDateFormatter *sdateFormatter = [[NSDateFormatter alloc] init];
sdateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[sdateFormatter setDateFormat:@"E MMM d yyyy HH:mm:ss 'GMT'zzz '(IST)'"];
NSDate *sdate = [sdateFormatter dateFromString:stringDate];
于 2014-11-05T05:45:05.717 回答
1
@"Sun Feb 24 2013 00:00:00 GMT+0530 (India Standard Time) " 

消除

 (India Standard Time) 

然后进行格式化

NSString  *dateStr = @"Sun Feb 24 2013 00:00:00 GMT+0530" ;
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"EE LLLL dd yyyy HH:mm:ss Z"];
    NSDate *date = [dateFormat dateFromString:dateStr];
    [dateFormat setDateFormat:@"dd-MM-yyyy"];

    NSLog(@"%@",[dateFormat stringFromDate:date]);
于 2013-03-14T06:24:42.740 回答
0

试试这个

NSString  *dateStr = @"Sun Feb 24 2013 00:00:00 GMT+0530 (India Standard Time) " ;
NSString *clippedString = [dateStr substringToIndex:dateStr.length - 23];

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"EE LLLL dd yyyy HH:mm:ss Z"];

NSDate *date = [formatter dateFromString:clippedString];

[formatter setDateFormat:@"yyyy-MM-dd hh:mm:ss a"];
NSString *newDateString = [formatter stringFromDate:date];
于 2013-03-14T06:30:15.980 回答
0

首先去掉“GMT+0530(印度标准时间)”文字,

    NSString  *dateStr = @"Sun Feb 24 2013 00:00:00" ;
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
   [dateFormat setDateFormat:@"EEE MMM d yyyy HH:mm:ss"];
    NSDate *date = [dateFormat dateFromString:dateStr];
于 2013-03-14T06:32:31.670 回答
0

试试这个:它对我有用

NSString  *dateStr = @"Sun Feb 24 2013 00:00:00 GMT+0530";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EE MMM d yyyy HH:mm:ss Z"];

NSDate *date = [[NSDate alloc] init];
date = [dateFormat dateFromString:dateStr];
于 2013-03-14T06:32:46.093 回答
0
NSString  *dateStr = @"Sun Feb 24 2013 00:00:00 GMT+0530" ;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC+0530"]];
[dateFormatter setDateFormat:@"EE LLL dd yyyy HH:mm:ss zzz"];
NSDate *date = [dateFormatter dateFromString:dateStr];


[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss a"];
NSString *newDateString = [dateFormatter stringFromDate:date];
NSLog(@"date : %@",newDateString);
于 2013-03-14T06:48:37.240 回答