1

我正在尝试使用 NSDateFormatter 将诸如 2013-02-08T10:50:00.000 的 NSString 转换为上午 10:50,无论我做什么,我似乎都无法获得 AM 或让它与 12 岁以上的东西一起工作(2013-02-08T15:00:00.000) 有什么想法吗?

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"HH-mm"];
    NSString *datelocalformat= [dateFormatter stringFromDate:DepartTimeString];
4

1 回答 1

0
NSDate *today = [NSDate date];//get today's date
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
 NSString *dateString = [dateFormatter stringFromDate:today];
[dateFormatter release];

// Get time - display in 12HR
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setTimeStyle:NSDateFormatterLongStyle];
NSString *timeString = [timeFormatter stringFromDate:today];
[timeFormatter release];
于 2013-02-10T23:20:36.980 回答