全局处理时的日期时间问题是日光 [英] Date time issue while handling globally with is daylight

查看:91
本文介绍了全局处理时的日期时间问题是日光的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们必须节省挪威时间 9:00

如果我们忽略日光。在中的数据库UTC 我们将保存 8:00 。在显示中,我们将为挪威 9:00 添加 +1 。在印度,我们正在添加 +5:30 表示 1:30 - 它应该是 12 :30 ,1小时差价



如果我们考虑日光,那么我们应该添加用户 +2 for Norway手段在数据库中我们将保存 7:00 对于挪威的 +2 它将是 9:00 对于印度,它将 12:30 - 正确的时间。但是在这种情况下,如果我们想要查看我们在白天灯亮时添加的旧日期 +1 但是现在如果我们通过添加 +2 小时。然后它将提前1小时。



我的问题



什么我正在做的是获取用户输入的本地时间。



并通过为用户时区添加偏移小时将其转换为UTC。



当我将用户时区的偏移小时传递给SQL和SQL时,我将UTC日期转换为用户当地时间。



和这里这个问题出现了我在3月31日之前输入+1的旧日期。在3月31日之后,由于日光,用户偏移将为+2。旧日期转移了一小时。





如果我在处理日期时遇到错误,请纠正我。

如何解决我的问题

Suppose we have to save Norwegian time 9:00
If we are ignoring day light.In database in UTC we will save 8:00. In Display we will add +1 for Norway 9:00. In India we are adding +5:30 means 1:30 – it should be 12:30, 1 hour difference

If we consider day light then we should add user +2 for Norway Means in database we will save 7:00 And for Norway for +2 it will be 9:00 And for India it will be 12:30 – correct time. But in this case if we want to see old dates which we have added when day light was false with +1 But now if we show old dates by adding +2 hours. Then it will be 1 hour earlier.

MY Problem

What i am doing is getting local time entered by user.

and converting it to UTC by adding offset hour for user timezone.

And while getting i am passing offset hour for user timezone to SQL and in SQL i am converting UTC date to user local time.

and here the issue comes old dates which i have entered with +1 before 31 march.After 31 march as user offset will be +2 because of day light.So old dates shifted by one hour.


Please correct me where i am doing wrong in handling dates.
And how can i solve my problem

推荐答案

我会在数据库中保存为UniversalTime

I would save as UniversalTime in the database
var toSaveInDb=    TimeZone.CurrentTimeZone.ToUniversalTime(DateTime.Now)



然后你可以ge的任何国家返回如下:


then any country you can get it back as below

var fromDBtoUI  =  TimeZone.CurrentTimeZone.ToLocalTime(myUtcDateTime)





引用

http://msdn.microsoft.com/en-us/library/system.datetime.touniversaltime.aspx [ ^ ]

如何在C#中获得当地时间的UTC等价物 [< a href =http://stackoverflow.com/questions/12483084/how-to-get-utc-equivalent-for-my-local-time-in-c-sharptarget =_ blanktitle =New Window > ^ ]

您需要检测客户端文化并将其设置为当前线程文化。

http: //weblog.west-wind.com/posts/2014/Mar/27/Auto-Selecting-Cultures-for-Localization-in-ASPNET [ ^ ]



references
http://msdn.microsoft.com/en-us/library/system.datetime.touniversaltime.aspx[^]
How to get UTC equivalent for my local time in C#[^]
You need to detect client culture and set it as current thread culture.
http://weblog.west-wind.com/posts/2014/Mar/27/Auto-Selecting-Cultures-for-Localization-in-ASPNET[^]

这篇关于全局处理时的日期时间问题是日光的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆