1

When recording a TimeStamp into the the table in the DB why does...

DateTime todaysDate = DateTime.Today;

BookingRecord newBooking = new BookingRecord();
//other code for adding record to db
newBooking.TimeStamp = todaysDate;

why does the record in timeStamp record as : 2013-09-04 00:00:00.000 I want the correct time to display as well?

thanks for reply

4

3 回答 3

9

因为 DateTime.Today 实际上应该这样做。如果您还需要时间信息,请使用 DateTime.Now。

编辑:当然,无论如何建议使用 UTC DateTimes 存储在数据库中,所以最好使用 DateTime.UtcNow!

于 2013-09-04T16:11:18.723 回答
4

DateTime.Today实际上将是今天的日期,时间部分设置为00:00:00

http://msdn.microsoft.com/en-us/library/system.datetime.today.aspx

设置为今天日期的对象,时间组件设置为 00:00:00。

于 2013-09-04T16:11:45.910 回答
0
DateTime todaysDate = DateTime.Today;

改成

DateTime todaysDate = DateTime.Now;
于 2013-09-05T06:08:13.793 回答