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不允许比较不同类型.
秒是具有秒秒精度的双浮点值(以秒为单位). var sampleDate: Double = Double(sample.getStartDate()) 然后他们可以比较: if(sampleDate > cuttDate){} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |