c# - 获得时差
问题描述
您如何使用两种方法找到时间差异。以及如何使用 TimeSpan 调用减法两个方法。
static void Main(string[] args)
{
int baba;
var stopWatch = new StopWatch();
Console.WriteLine("Please enter in any value to get the start time");
string ti = Console.ReadLine();
baba = Convert.ToInt32(ti);
Console.WriteLine(baba);
stopWatch.Start();
Console.WriteLine(Console.Read());
if(ti != null)
{
stopWatch.Stop();
Console.WriteLine(Console.Read());
}
}
解决方案
请参阅评论中可能的重复链接。另一种计算时间差的方法是从 TimeSpan 中获取:
DateTime time1 = DateTime.Now;
Thread.Sleep(1000);
DateTime time2 = DateTime.Now;
TimeSpan ts = time2 - time1;
Console.WriteLine(ts.TotalMilliseconds);
推荐阅读
- r - 尝试在我的 netcdf 数据集的列表中创建一个列表
- vba - Word 2016-如何在受保护的文档中复制/粘贴选定的富文本内容控件-VBA?
- r - 是否有一种 R 方法可以保留数字并丢弃相同值的文本(例如 6 和一点)
- mysql - 如何同时运行 mysql Workbench 的 2 个选项?
- jsonata - JSONata 性能/效率假设
- flutter - 在 ChangeNotifier 的 addListener 回调中使用 setState
- spring-boot - 如何在 Spring Web 服务中设置自定义 EndpointExceptionResolver 的优先级
- reactjs - 从 API 返回结果并使用 react 显示
- python - 重定向标准输出时打印到终端
- java - 如何修复此代码以为每个用户进行收集?