根据时区的偏移量和后缀查找夏令时指示

发布于 2024-12-04 03:08:06 字数 218 浏览 1 评论 0原文

我正在使用地球工具网络服务来查找基于经纬度的时区。我在网络服务中获取偏移量和后缀。

Earth Tool Webservice

现在,我面临的问题是我需要从中获取时区偏移量和后缀并确定该地区是否有夏令时。我该怎么做?

i am using earth tool webservice to find time zone based on lat long. 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白日梦 2024-12-11 03:08:06

.Net 有一个很好的 TimeZoneInfo.Local.IsDaylightSavingTime,但不幸的是您没有足够的信息来创建实例。

但是,您应该能够执行以下操作:

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;

.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;
能怎样 2024-12-11 03:08:06

如果该 lang+lot 上有夏令时,您使用的 API 会返回,您不必从偏移量和后缀中找到它。

看看这个:

目的地
本地时间和等时时间元素是否包含
夏令时。如果他们这样做,这个元素的值将是
真的。如果不这样做,该值将为 False。如果不能的话
确定是否应使用夏令时,
值将为未知。自:1.1

如果您想自己确定,没有此属性,您必须知道指向的国家/地区,因为 DST 是特定于国家/地区的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文