加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift ios日期为毫秒Double或UInt64?

发布时间:2020-12-14 05:37:14 所属栏目:百科 来源:网络整理
导读:我不是iOS开发者,但是开始学习 Swift. 我尝试将一些逻辑从Android项目转换为iOS 我有以下方法: func addGroupItemSample(sample : WmGroupItemSample){ // some custom class var seconds: NSTimeInterval = NSDate().timeIntervalSince1970 var cuttDate:D
我不是iOS开发者,但是开始学习 Swift.

我尝试将一些逻辑从Android项目转换为iOS

我有以下方法:

func addGroupItemSample(sample : WmGroupItemSample){ // some custom class

    var seconds: NSTimeInterval = NSDate().timeIntervalSince1970
    var  cuttDate:Double =  seconds*1000;

    var sampleDate: UInt64 = sample.getStartDate(); // <-- problematic place

if(sampleDate > cuttDate){
   // ....
  }
}

从上面的方法可以看到,sample.getStartDate()返回类型为UInt64.

我以为它很像Java:System.currentTimeMillis()

但当前时间(以毫秒为单位)定义为Double.

混合Double和UInt64是否正确的方式,或者我需要代表所有毫秒为双倍?

谢谢,

Swift不允许比较不同类型.

秒是具有秒秒精度的双浮点值(以秒为单位).
sampleDate是一个UInt64,但没有给出单位.
sampleDate需要以秒为单位转换为双浮点值.

var sampleDate: Double = Double(sample.getStartDate())

然后他们可以比较:

if(sampleDate > cuttDate){}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读