我想将我的NSTimeInterval设置为00:00:00(小时、分钟、秒)的字符串格式.最好的方法是什么?

推荐答案

NSTimeInterval interval = ...;    
NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];    
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"HH:mm:ss"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
NSString *formattedDate = [dateFormatter stringFromDate:date];
NSLog(@"hh:mm:ss %@", formattedDate);

Objective-c相关问答推荐

将 NSInteger 转换为 NSIndexpath

viewWillAppear,viewDidAppear 没有被调用,没有触发

如何追踪 SIGABRT 的原因

UITableViewCell 突出显示时使标签的背景清晰

如何创建 NSIndexPath:indexPathWithIndexes:length 所需的索引:

在可可中的字符串上使用 MD5 哈希?

ARC的正确桥接?

如何在 iPhone 上显示来自 API 的 HTML 文本?

如何将日期字符串解析为 iOS 中的 NSDate 对象?

如何转储存储在 Objective-C 对象(NSArray 或 NSDictionary)中的数据

无法加载从笔尖引用的图像

StoryBoard 助理编辑器停止显示相关文件

在 Objective C 中使用 extern

MKAnnotation 图像偏移与自定义引脚图像

Xcode:无法判断应用程序包

创建 NSTextField标签的示例代码?

@dynamic 在 Objective-C 中做了什么?

Xcode 警告未使用属性访问结果 - getter 不应用于副作用

CMTime 秒输出

判断 UIViewController 是否即将从导航堆栈中弹出?