不同版本的.NET Framework的DateTime值不同 [英] DateTime value is different across different versions of .NET framework
问题描述
我有一个服务(语言:VB.NET,框架:.NET 3.5),该服务返回从中读取日期的数据集。数据库中的列的值为: 1980-03-30 00:00:00.000。
I have a service(Language: VB.NET, Framework:.NET 3.5) that returns a dataset from which I read a date. The value of the column in the database is: "1980-03-30 00:00:00.000".
在使用.NET 3.5的客户端(语言:C#)中,该值的显示时间为:1980年3月30日上午12:00:00
In a client(Language: C#) that uses .NET 3.5, the value is coming thorough as : 3/30/1980 12:00:00 AM
但是,当我将同一客户端更改为使用.NET 4或.NET 4.5时,通过该服务提供的日期为:1980/3/29下午11:00:00
However, when I change the same client to use .NET 4 or .NET 4.5, the date which comes through the service is: 3/29/1980 11:00:00 PM
推荐答案
DateTime
值的差异不是因为.Net框架,这是由于区域设置所致。
The difference in DateTime
values is not because of .Net framework, its because of the locale settings.
不要通过Web服务传递 DateTime
值,请传递 DateTimeOffset
然后进行转换在客户端中输入 DateTime
。
Never pass DateTime
values through your web service, pass DateTimeOffset
and then convert to DateTime
type in your client.
这篇关于不同版本的.NET Framework的DateTime值不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!