开发者

finding daylight saving indication based on offset and suffix of time zone

开发者 https://www.devze.com 2023-04-03 20:08 出处:网络
i am using earth tool webserviceto find time zone based on lat lo开发者_开发技巧ng. I am getting offset and suffix in the webservice.

i am using earth tool webservice to find time zone based on lat lo开发者_开发技巧ng. I am getting offset and suffix in the webservice.

Earth Tool 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 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;


The API you are using returns if there is daylight saving on that lang+lot, you don't have to find it out from offset and suffix.

See this:

dst
Whether or not the localtime and isotime elements include daylight saving time. If they do, the value of this element will be True. If they do not, the value will be False. If it can't be determined whether or not daylight saving time should be used, the value will be Unknown. Since: 1.1

If you would like to determine it your own, without this attribute, you have to know the country where to point is, because DST is country specific.

0

精彩评论

暂无评论...
验证码 换一张
取 消