[英]Convert NSString to NSDate and timeZone?
Ive been racking my brains with no luck. 我运气不佳。 Could someone please tell my how i would convert this string: 有人可以告诉我如何转换此字符串:
NSString *dateTimeStr =[[self.responseArray objectAtIndex:indexPath.row]objectForKey:@"date_time"];
2014-04-13T17:00:00+11:0 2014-04-13T17:00:00 + 11:0
into a NSDate
? 进入NSDate
? and time format ? 和时间格式?
how can i covert this date into time format ? 我如何将此日期转换为时间格式?
here is my code: 这是我的代码:
NSString *dateTimeStr =[[self.responseArray objectAtIndex:indexPath.row]objectForKey:@"date_time"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
[dateFormatter setDateFormat:@"yyyy-MM-ddHH:mm:ss"];
NSDate *date = [dateFormatter dateFromString:dateTimeStr];
NSLog(@"date %@", date);
NSTimeInterval seconds = [date timeIntervalSinceReferenceDate];
in console 在控制台中
NSLog(@"seconds==> %f", seconds);
i have time in miliseconds then how can i take out minutes/hours/
? 我的时间以毫秒为单位,那么我该如何计算minutes/hours/
?
NSString *dateString = @"2014-04-13T17:00:00+11:00";
NSDateFormatter *dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSDate *date = [dateFormatter dateFromString:dateString];
NSDateComponents *dateComponents = [[NSCalendar currentCalendar]
components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit
fromDate:date];
NSInteger year = [dateComponents year];
NSInteger month = [dateComponents month];
NSInteger day = [dateComponents day];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.