Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# UTC日期时间问题(C)#_C#_Datetime - Fatal编程技术网

C# UTC日期时间问题(C)#

C# UTC日期时间问题(C)#,c#,datetime,C#,Datetime,在控制台应用程序中,我设置UTC日期时间值: class Program { static readonly DateTime batchDateTime_UTC = DateTime.UtcNow; } 然后我主要在方法中使用上述变量: static void Main(string[] args) { Parallel.ForEach(lst_Systems.AsEnumerable(), item => { GetRecordsForT

在控制台应用程序中,我设置UTC日期时间值:

class Program
{
   static readonly DateTime batchDateTime_UTC = DateTime.UtcNow;
}
然后我主要在方法中使用上述变量:

static void Main(string[] args)
{
     Parallel.ForEach(lst_Systems.AsEnumerable(), item =>
     {
          GetRecordsForTimeRange(item.IP, batchDateTime_UTC);
     }
}
此方法正在将数据插入数据库。 我的问题是,当我在数据库中检查batchDateTime_UTC值时,它有两个不同的值:

2015-09-17 10:03:00.000
2015-09-17 10:03:36.000

我发现问题是由我的存储过程引起的,该存储过程在源表中找不到任何记录的情况下向表中插入空白值。
我使用了CONVERT(nvarchar(100),@BatchDateTime)并将其更改为CONVERT(nvarchar(100),@BatchDateTime,120),现在秒数没有减少。

您能再向我们展示一下数据是如何写入数据库的吗?您确定不只是运行了两次程序,相隔36秒?似乎您需要36秒才能将项目添加到数据库中,更多代码将被删除helpful@simonalexander2005-我正在使用SqlBulkCopy复制数据。@AakashM我确信程序不会启动两次,因为时差仅适用于某些IP范围