计算两次之间的时间

编程入门 行业动态 更新时间:2024-10-27 18:27:54
本文介绍了计算两次之间的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好 我想写一个方法; 一开始开始时间 2次结束时间 3-计算它们之间的时间 也用于日期: 一开始获取日期 2次获取结束日期 3-计算它们之间的日期 请大家帮忙,谢谢大家.

Hello All i want to write a method; 1-get start time 2-get end time 3-calculate time between them also for date: 1-get start date 2-get end date 3-calculate date between them please help,thanks everyone

推荐答案

根据需要进行修改. Modify as required. // Times DateTime time1 = DateTime.Parse("22:00"); DateTime time2 = DateTime.Parse("23:45"); TimeSpan timeDiff = time2 - time1; Console.WriteLine("There are " + timeDiff.Minutes + " minutes between the two times."); // Dates DateTime date1 = DateTime.Parse("17 March 2012"); DateTime date2 = DateTime.Parse("14 June 2012"); TimeSpan dateDiff = date2 - date1; Console.WriteLine("There are " + dateDiff.Days + " days between the two dates."); Console.ReadLine();

请参阅 TimeSpan类 [ ^ ]用于增量时间和日期时间类 [ ^ ]绝对时间. 干杯 Andi See TimeSpan Class[^] for delta times and DateTime Class[^] for absolute times. Cheers Andi

请检查以下示例. Please check the below example. static void Main(string[] args) { DateTime tm1 = DateTime.Parse("05:35"); DateTime tm2 = DateTime.Parse("13:57"); TimeSpan ts = (tm2 - tm1); Console.WriteLine(ts); DateTime dt1= DateTime.Parse("5/12/2012"); DateTime dt2 = DateTime.Parse("7/12/2012"); int days = (dt2 - dt1).Days; Console.WriteLine(days); Console.Read(); }

这将返回u 08:22(时差) 2(日期差异)

This will return u 08:22(time diff) 2(date diff)

更多推荐

计算两次之间的时间

本文发布于:2023-10-27 03:50:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1532224.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两次   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!