ios - 在ios中读取UTC并减去迄今为止的时间

标签 ios ios5 ios6

我从服务器获取日期时间(截止日期)字符串,如“2013-03-29 04:12:35”,我需要制作秒表,它将在标签中显示截止日期的估计时间格式小时::分钟:秒。我想将截止日期转换为 utc,然后从手机读取当前 utc,减去并转换为格式小时::分钟:秒。如何在ios中读取UTC并将字符串转换为UTC(是否有更简单的方法来完成此任务)?

最佳答案

试试这个

NSString *utcDateString = @"2013-03-29 04:12:35";

NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
//DateFormatter by default will be in local timezone.
[formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
[formatter setFormat:@"yyyy-MM-dd HH:mm:ss"];

NSDate *utcDate = [formatter dateFromString:utcDateString];

NSDate *currentDate = [NSDate date];

现在您可以使用post.中提到的方法来查找日期组成部分(小时,分钟,秒)

关于ios - 在ios中读取UTC并减去迄今为止的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15350002/

相关文章:

iOS - 今天扩展 'show more' 和 'show less' 状态不正确。折叠显示 'show less' - 需要多次按下才能修复

ios - 向 ActionSheet 添加按钮时出现 NSInvalidArgumentException

ios - 在 iOS 5 上关闭 UIImagePickerController 后出现白屏?

ios - 等待开发者发布

iphone - 从 self.navigationItem(在 UINavigationController 内部)打开时,UIPopoverController 未解除

ios - iPad 中 RTL 语言导航按钮的位置不正确

ios - MFMailComposeViewController 不会关闭 (iOS10)

ios - 如何使用 AutoLayout 在 NavigationBar 下方添加 UITableView?

ios - 如何知道 AfNetworking 是否已下载所有图像

iphone - Xcode - 本地化图像无法在设备上运行