swift:计算时间差
来源:互联网 发布:贵阳公安数据铁笼 编辑:程序博客网 时间:2024/05/17 09:30
//获取日期差,yyyy-MM-dd HH:mm:ss格式
func intervalSinceNow(_ fromdate:Date) -> String{
let format = DateFormatter.init()
format.dateFormat ="yyyy-MM-dd HH:mm:ss"
let fromZone = TimeZone.current
let fromInterval = fromZone.secondsFromGMT(for: fromdate)
let fromDate = fromdate.addingTimeInterval(Double(fromInterval))
let adate = Date()
let zone =TimeZone.current
let interval = zone.secondsFromGMT(for: adate)
let localeDate = adate.addingTimeInterval(Double(interval))
let interValTime = fromDate.timeIntervalSinceReferenceDate - localeDate.timeIntervalSinceReferenceDate
let lTime = fabs(interValTime)
let iSeconds = Int(lTime.truncatingRemainder(dividingBy: 60))
let iMinutes = Int((lTime / 60) / 60)
let iHours = Int(fabs((lTime / 3600).truncatingRemainder(dividingBy:24)))
let iDays: Int = Int(lTime / 60 / 60 / 24);
// let iMonth = Int(lTime / 60 / 60 / 24 / 12);
// let iYears = Int(lTime / 60 / 60 / 24 / 384);
var timeString = ""
if (iHours<1 && iMinutes>0)
{
timeString = "\(iMinutes)\(locationTextValue("mins", str_cht:"分", str_chs: "分"))"
}else if (iHours>0&&iDays<1 && iMinutes>0) {
timeString = "\(iHours)\(locationTextValue("hour", str_cht:"時", str_chs: "時"))\(iMinutes) \(locationTextValue("mins", str_cht:"分", str_chs: "分"))"
}
else if (iHours>0&&iDays<1) {
timeString = "\(iHours)\(locationTextValue("hour", str_cht:"時", str_chs: "时"))"
}else if (iDays>0 && iHours>0)
{
timeString = "\(iDays)\(locationTextValue("day", str_cht:"天", str_chs: "天"))\(iHours) \(locationTextValue("hour", str_cht:"時", str_chs: "時"))"
}
else if (iDays>0)
{
timeString = "\(iDays)\(locationTextValue("Day", str_cht:"天", str_chs: "天"))"
} else {
timeString = "\(iSeconds)\(locationTextValue("seconds", str_cht:"秒", str_chs: "秒"))"
}
return timeString
}
- swift:计算时间差
- SWIFT和Android中计算时间差
- 时间差计算
- 计算时间差
- 计算时间差
- 计算时间差
- 时间差计算
- 计算时间差
- 时间差 计算
- 计算时间差
- 计算时间差
- 计算时间差
- 计算时间差
- 计算时间差
- 计算时间差
- 时间差计算
- 计算时间差
- 计算时间差
- 阿里云总裁胡晓明:AI泡沫过后,下一站是“产业AI”
- git远程分支与本地分支合并
- android默认开启adb调试方法分析
- 林轩田之机器学习课程笔记(when can machines learn之learning problem)(32之1)
- spring事务-说说Propagation及其实现原理(传播属性示例分析)
- swift:计算时间差
- 专访阿里云游戏首席架构师李刚:如何解决云服务技术两大痛点?
- python两个子线程通过queue通信
- 第四周 【项目1
- 在Eclipse中使用Git
- 深度学习优化算法(sgd/momentum/Nesterov/adagrad/adadelta)
- 使用git将项目上传到github(最简单方法)
- 浅谈IT行业风投
- can't call void android.view.View.setElevation(float) on null obj in call to CallVoidMethodV