Unity 计算两个日期的时间差(含绝对值计算方法)

//添加引用

using system;

DateTime marriedTime = Convert.ToDateTime("2024-04-01 08:08:08");

DateTime nowTime = DateTime.Now;

TimeSpan timeSpan2 = new TimeSpan(marriedTime.Ticks);

TimeSpan timeSpan1 = new TimeSpan(nowTime.Ticks);

//方式1:计算两个时间差的绝对值

TimeSpan timeSpanSub = timeSpan1.Subtract(timeSpan2).Duration();

//方式1:计算两个时间差的真实值(大于正数,小于负数)

TimeSpan timeSpanSub = nowTime - marriedTime;//

int nDays = timeSpanSub.Days; //差值:天数

int nHours = timeSpanSub.Hours; //差值:小时

int nMinutes = timeSpanSub.Minutes; //差值:分钟

相关推荐
hhh3u3u3u12 小时前
Visual C++ 6.0中文版安装包下载教程及win11安装教程
java·c语言·开发语言·c++·python·c#·vc-1
加号312 小时前
【C#】实现沃德普线光控制器通信控制(附完整源码)
开发语言·c#
lzhdim13 小时前
SharpCompress:跨平台的 C# 压缩与解压库
开发语言·c#
~plus~15 小时前
.NET 8 C# 委托与事件实战教程
网络·c#·.net·.net 8·委托与事件·c#进阶
beyond谚语16 小时前
接口&抽象类
c#·接口隔离原则·抽象类
新手小新16 小时前
C#学习笔记1-在VS CODE部署C#开发环境
笔记·学习·c#
rockey62719 小时前
AScript动态脚本多语言环境支持
sql·c#·.net·script·eval·function·动态脚本
ou.cs20 小时前
c# SemaphoreSlim保姆级教程
开发语言·网络·c#
龙侠九重天20 小时前
ML.NET 实战:快速构建分类模型
分类·数据挖掘·c#·.net
fengyehongWorld21 小时前
C# 创建Worker,杀死指定程序的线程
c#