C# 获取日期时间对象

C# 获取日期时间对象,c#,datetime,datetime-format,C#,Datetime,Datetime Format,嗨,我想要一个datetime对象。我想自己设定一段时间 就像我想要DateTime对象,该对象将具有todays系统日期,我想将其时间设置为08:00:00。给您: 给你: 将在下午6点为您提供当前日期的日期值 将在下午6点为您提供当前日期的日期值。DateTime dt=new DateTime(DateTime.Today.Year,DateTime.Today.Month,DateTime.Today.Day,8,0,0) 我想这是最简单的,在另一种情况下,您也可以在DateTime上

嗨,我想要一个datetime对象。我想自己设定一段时间

就像我想要DateTime对象,该对象将具有todays系统日期,我想将其时间设置为08:00:00。

给您:

给你:

将在下午6点为您提供当前日期的日期值


将在下午6点为您提供当前日期的日期值。

DateTime dt=new DateTime(DateTime.Today.Year,DateTime.Today.Month,DateTime.Today.Day,8,0,0)

我想这是最简单的,在另一种情况下,您也可以在DateTime上创建一个扩展方法来返回上述内容


扩展方法还允许您调用类似于
DateTime.MyToday()
的函数,它将返回当前日期,默认时间设置为8:00:00。因此,您不需要执行整个
newdatetime(DateTime.Today.Year,DateTime.Today.Month,DateTime.Today.Day,8,0,0)
每次需要此类日期时。

DateTime dt=new DateTime(DateTime.Today.Year,DateTime.Today.Month,DateTime.Today.Day,8,0,0)

DateTime meetingAppt = new DateTime(
    DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 0, 0);
我想这是最简单的,在另一种情况下,您也可以在DateTime上创建一个扩展方法来返回上述内容


扩展方法还允许您调用类似于
DateTime.MyToday()
的函数,它将返回当前日期,默认时间设置为8:00:00。因此,您不需要执行整个
newdatetime(DateTime.Today.Year,DateTime.Today.Month,DateTime.Today.Day,8,0,0)
每次你都需要这样的日期。

每天无法找到内置于他们语言中的
DateTime
结构的人数令人担忧。每天无法找到内置于他们语言中的
DateTime
结构的人数令人担忧。DateTimemeetingAppt=新的日期时间(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,08,00,0);DateTime meetingAppt=新的日期时间(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,08,00,0);
DateTime meetingAppt = new DateTime(
    DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 0, 0);