String 从字符串解析NSDate
方法dateFromString的返回时间始终大于一小时。示例: 字符串“2013-08-3100:00:00”->NSDate“2013-08-3101:00:00 MSK” 字符串“2013-08-3111:59:59”->NSDate“2013-08-3112:59:59 MSK” 我试试这个:String 从字符串解析NSDate,string,nsdate,String,Nsdate,方法dateFromString的返回时间始终大于一小时。示例: 字符串“2013-08-3100:00:00”->NSDate“2013-08-3101:00:00 MSK” 字符串“2013-08-3111:59:59”->NSDate“2013-08-3112:59:59 MSK” 我试试这个: [dateFormat setTimeZone:[NSTimeZone localTimeZone]]; and [dateFormat setTimeZone:[NSTimeZone defa
[dateFormat setTimeZone:[NSTimeZone localTimeZone]]; and
[dateFormat setTimeZone:[NSTimeZone defaultTimeZone]];
结果是一样的
这是:
[dateFormat setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
字符串“2013-08-3100:00:00”->NSDate“2013-08-3105:00:00 MSK”(+4小时)
我需要获得字符串中的时间:
字符串“2013-08-31 00:00:00”->NSDate“2013-08-31 00:00:00 MSK”
我如何做到这一点?使用以下工具,它对我来说很好:
+(NSString *)getDateInStringFormat:(NSDate *)creationDate {
NSDateFormatter *createDateFormatter = [[NSDateFormatter alloc]init];
[createDateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
[createDateFormatter setDateFormat:@"YYYY-MM-dd'T'HH:mm:ss"];
NSString *currentDateString = [createDateFormatter stringFromDate:creationDate];
//NSLog(@"Prfile creation date is = %@",ProfileCreationDate);
return currentDateString;
}
我需要从字符串获取NSDate,而不是从NSDate获取字符串。我还尝试:[dateFormat setTimeZone:[NSTimeZone TimeZoneWithAbRevision:@“GMT”]];-这无助于:(