我使用以下方法将NSDate转换为NSString
- (void)splitDateintoDateTime:(NSDate *)date
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"dd/MM/yyyy"];
strDate = [formatter stringFromDate:date];
[formatter setDateFormat:@"hh:mm a"];
strTime = [formatter stringFromDate:date];
}
date
的格式为yyyy-MM-dd hh:mm:ss z
我希望Date
和Time
的单独NSDate值采用方法中提到的格式。
答案 0 :(得分:-1)
- (void)splitDateintoDateTime:(NSDate *)date
{
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc]init]autorelease];
dateFormatter.dateFormat = @"dd/MM/yyyy";
NSString *dateString = [dateFormatter stringFromDate: date];
NSDateFormatter *timeFormatter = [[[NSDateFormatter alloc]init]autorelease];
timeFormatter.dateFormat = @"HH:mm z";
NSString *dateString = [timeFormatter stringFromDate: date];
}