在C#创建一个午夜日期时间的最佳方法 [英] Best way to create a Midnight DateTime in C#

查看:133
本文介绍了在C#创建一个午夜日期时间的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个午夜的DateTime

I need to create a midnight DateTime

我刚刚做了这一点:

DateTime endTime = DateTime.Now;
endTime.Subtract(endTime.TimeOfDay);



还没有测试它,我假设它的工作原理,但有没有更好/更清洁的方式?

Haven't test it yet, I'm assuming it works but is there a better/cleaner way?

推荐答案

只需使用 foo.Date DateTime.Today 为今天的日期

just use foo.Date, or DateTime.Today for today's date

这篇关于在C#创建一个午夜日期时间的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆