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; //差值:分钟

相关推荐
geovindu13 小时前
CSharp: Breadth First Search Algorithm and Depth First Search Algorithm
开发语言·后端·算法·c#·.net·搜索算法
小羊先生car17 小时前
RTOS-F429-HAL-(动/静态)任务的创建(2026/7/27)
开发语言·算法·c#
地球驾驶员18 小时前
NX二次开发C#-获取体的外表面
开发语言·c#
向夏威夷 梦断明暄19 小时前
从 Bun 的 Rust 重写,看 C# 如何重建 AI 基础设施层
人工智能·rust·c#
心平气和量大福大20 小时前
C#-WPF-控件-LiveChart图表-线性2(LineSeries)-数据绑定
开发语言·c#·wpf
海盗123421 小时前
微软技术周报2026-07-27
microsoft·c#·.net
code bean1 天前
【C#】 `Channel<T>` 深度解析:生产者-消费者模式的现代解法
数据结构·c#
吴可可1232 天前
C# CAD二次开发:合并首尾重合多段线
c#
EIP低代码平台2 天前
EIP低代码平台 - 应用管理 - 表单设计
低代码·c#·权限·工作流·netcore
czhc11400756632 天前
726:zoffset
c#