c#中有个函数是Datetime.Now()获取时间,我在大部分时候能够正确获取,但是最近在给客户调试时,却出现了0000:00:00的数据,请教大家这是由于什么原因引起的?
以下是我获取的数据: 
2009-07-23 15:25:02
2009-07-23 15:25:03
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00

解决方案 »

  1.   

    获取时间的代码就是Datetime.Now();
    前两条数据是在笔记本是上进行测试的,下面全部为0的是在另外一台机子上进行测试的,我感觉应该是电脑设置的问题,但是不知到具体的原因!!
      

  2.   

    string sql = "insert into scan values('" + hostname + "','" + ipaddress + "','" + worknumber + "','" + productSN + "','" + errorcode + "','" + comConvert(comport) + "','" + DateTime.Now + "');";
      

  3.   

    string sql = "insert into scan values('" + hostname + "','" + ipaddress + "','" + worknumber + "','" + productSN + "','" + errorcode + "','" + comConvert(comport) + "'," + DateTime.Now + ");";没不要要引号,如果不行,你就采用服务器的时间不是更好string sql = "insert into scan values('" + hostname + "','" + ipaddress + "','" + worknumber + "','" + productSN + "','" + errorcode + "','" + comConvert(comport) + "',getdate());";
      

  4.   

    是北京时间和格林尼治时间差8个小时。.ToLocal 就可以了
      

  5.   

    你写不是SQL语句吗?如果是SQL Server用GetDate().