如何在C#中获取当前日期和时间
Hello Team,
这是一个非常简单的问题,但我不知道为什么会发生这种情况。
我想要当前的日期和时间C#。
我正在尝试这个:
customerLoanRecord.CreatedOn = DateTime.Now.Date;
I我得到的日期,但我看不到时间。为时间,我该怎么办。
i需要DateandTime。
感谢
harshal raut
Hello Team,
it a very simple question but i dont know why its happening.
I want current Date and Time in C#.
I am Trying this:
customerLoanRecord.CreatedOn = DateTime.Now.Date;
I am getting the date but i cant see the time .So for Time what should i do .
i required both DateandTime.
Thank
harshal raut
取消Date一词:
Take off the word "Date":
customerLoanRecord.CreatedOn = DateTime.Now;
DateTime对象的Date属性删除所有时间信息!
The Date property of a DateTime object removes all time information!
customerLoanRecord.CreatedOn = DateTime.Now.Date;
customerLoanRecord.CreatedOn = DateTime.Now.Date;
这应该是:
This should be:
customerLoanRecord.CreatedOn = DateTime.Now;
(假设 customerLoanRecord.CreatedOn
类型是日期时间
)
将CreatedOn声明为属性,然后检查。
Declare CreatedOn as a property and then check.
private DateTime _CreatedOn = new DateTime();
public DateTime CreatedOn
{
get
{
_CreatedOn = DateTime.Now;
return _CreatedOn;
}
set
{
_CreatedOn = value;
}
}