NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
// 把時間設定成世界時間
//[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate* date = [dateFormatter dateFromString:@"Date String"];
[dateFormatter release];
// 把時間設定成世界時間
//[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate* date = [dateFormatter dateFromString:@"Date String"];
[dateFormatter release];
NSDate to NSString
NSDateFormatter* outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString* dateString = [outputFormatter stringFromDate:date];
[outputFormatter release];
[outputFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString* dateString = [outputFormatter stringFromDate:date];
[outputFormatter release];
沒有留言:
張貼留言