使用SwiftDate将日期转换为多种格式 您所在的位置:网站首页 分钟转换时间格式 使用SwiftDate将日期转换为多种格式

使用SwiftDate将日期转换为多种格式

2023-03-28 19:32| 来源: 网络整理| 查看: 265

为什么不使用this库?您可以导入NSDateTimeAgo.bundle和NSDate+Extension.swift。并将您的时间戳转换为可以说1小时17分钟,你可以这样做:

let timestamp = //timestamp or time let date = Date(timeIntervalSince1970: timestamp!) let timeAgo = date.timeAgo print(timeAgo)

我建议你这样做,因为它更轻量。如果你不需要“前”,那么你可以从NSDateTimeAgo.string文件中删除那些。

但你也可以不用这样如任何库秒:

func secondsToHoursMinutesSeconds (seconds : Int) -> (Int, Int, Int) { return (seconds/3600, (seconds % 3600)/60, (seconds % 3600) % 60) } func secondsToHoursMinutesSeconds (seconds:Int) ->() { let (h, m, s) = secondsToHoursMinutesSeconds (seconds: seconds) print ("\(h) Hours, \(m) Minutes, \(s) Seconds") } secondsToHoursMinutesSeconds(seconds: 3000)// it would print 0 Hours, 50 Minutes, 0 Seconds

您也可以适应它为您的需求(此代码是从this答案)。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有