根据时区的偏移量和后缀查找夏令时指示 [英] finding daylight saving indication based on offset and suffix of time zone
本文介绍了根据时区的偏移量和后缀查找夏令时指示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用地球工具网络服务根据经纬度查找时区.我在网络服务中得到了偏移量和后缀.
i am using earth tool webservice to find time zone based on lat long. I am getting offset and suffix in the webservice.
现在我面临的问题是我需要从偏移量和后缀中获取时区,并确定该地区是否存在夏令时.我该怎么做?
Now the problem, i am facing is i need to get time zone from the offset and suffix and determine if there is daylight saving in the area or not. how can i do this?
推荐答案
.Net 有一个很好的 TimeZoneInfo.Local.IsDaylightSavingTime,但不幸的是你没有足够的信息来创建一个实例.
.Net has a nice TimeZoneInfo.Local.IsDaylightSavingTime, but unfortunately you don't have enough info to create an instance.
但是,您应该能够执行以下操作:
You should however be able to do something like this:
var offSet = -7;
var utcDateTimeStr = "2011-09-10 22:15:38";
var localWithDSStr = "10 Sep 2011 15:15:38";
// utc time
DateTime utcDateTime = DateTime.SpecifyKind(
DateTime.Parse(utcDateTimeStr), DateTimeKind.Utc);
// time taking into account daylight savings
DateTime localWithDS = DateTime.SpecifyKind(
DateTime.Parse(localWithDSStr), DateTimeKind.Local);
// time not taking into account daylight savings
DateTime localWithoutDS = utcDateTime.AddHours(offSet);
// is the time given adjusted for daylight savings
TimeSpan diff = (localWithoutDS - utcDateTime);
bool isDayLightSaving = diff.Hours != offSet;
这篇关于根据时区的偏移量和后缀查找夏令时指示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文