我想以这种格式设置时间。
“2012-09-27 12:03:33+05:30”
请告诉我该怎么做。
Take a look at NSDateFormatter. Below there is a sample..
NSString *dateString=...your_Date_String_Here..
NSDateFormatter* fmt = [NSDateFormatter new];
[fmt setTimeZone:[NSTimeZone defaultTimeZone]];
[fmt setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate* dateFromString = [fmt dateFromString:dateString];
检查NSDateFormatter文档。要准确获得您正在寻找的输出,您应该这样做:
NSDate *date = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ssZZZZZ"];
NSLog(@"%@", [dateFormatter stringFromDate:date]);