Unity3d 计算日期差、时间差

阅读 67

2023-08-18

       //C#对时间差有一个专门封装的类: TimeSpan.cs;
        DateTime marriedTime = Convert.ToDateTime("2021-07-01 08:08:08");
        DateTime nowTime = DateTime.Now;
        TimeSpan timeSpan1 = new TimeSpan(marriedTime.Ticks);
        TimeSpan timeSpan2 = new TimeSpan(nowTime.Ticks);
        TimeSpan timeSpanSub = timeSpan1.Subtract(timeSpan2).Duration();
        //timeSpanSub.Days:相差天数   timeSpanSub.Hours:相差小时    timeSpanSub.Minutes:相差分钟
        Debug.Log($"We are married:   {timeSpanSub.Days}    {timeSpanSub.Hours}  {timeSpanSub.Minutes}");

精彩评论(0)

0 0 举报