如何在 Objective-C 中将 NSDate 转换为毫秒? [英] How to convert NSDate to milliseconds in Objective-C?

查看:101
本文介绍了如何在 Objective-C 中将 NSDate 转换为毫秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:假设 NSDate tempdate = "05-23-2013".我希望将此值转换为毫秒.

我怎样才能用 Objective-C 做到这一点?

解决方案

有一个类似的帖子 此处此处.>

基本上,您已经获得了参考日期(2001 年 1 月 1 日,格林威治标准时间)的第二个表格并将其乘以 1000.

NSTimeInterval seconds = [NSDate timeIntervalSinceReferenceDate];双毫秒 = 秒*1000;

干杯!

For example: assume NSDate tempdate = "05-23-2013". I want this value to be converted into milliseconds.

How can I do this with Objective-C?

解决方案

There is a similar post here and here.

Basically you have get the second form the reference date (1 January 2001, GMT) and multiply it with 1000.

NSTimeInterval seconds = [NSDate timeIntervalSinceReferenceDate];
double milliseconds = seconds*1000;

Cheers!

这篇关于如何在 Objective-C 中将 NSDate 转换为毫秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆