0

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?

Adnan Zameer
  • 732
  • 3
  • 10
  • 23
  • Do you have to use that particular web service? Why do you need to know whether the offset includes DST out of interest? – Jon Skeet Sep 10 '11 at 22:34

2 Answers2

1

.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;
TheCodeKing
  • 19,064
  • 3
  • 47
  • 70
  • thanks but what i am trying to do is i have a offset and suffix and i get the local time of the server and get the Universal time from that `TimeZone tz = TimeZone.CurrentTimeZone; DateTime SystemTime = DateTime.Now; DateTime Usertime = tz.ToUniversalTime(SystemTime).AddHours(int.Parse(TimeStamp));` – Adnan Zameer Sep 11 '11 at 08:21
  • Universal time is in the feed already, so is the timezone's local time. I don't understand how your code relates to your question regarding the feed, or what you are trying to do. To can get *your* server UTC time using `DateTime.UtcNow`. – TheCodeKing Sep 11 '11 at 11:01
0

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.

norbip
  • 625
  • 7
  • 21
  • Thanks actually the idea is i am saving the suffix and offset from API into the database against a spot world wide...so that when ever in future i want to retrieve the spot info i should get the local time accordingly. The API indeed specify the daylight saving attribute but in future i will be not able to find from the database that its indeed a daylight saving there or not. – Adnan Zameer Sep 11 '11 at 07:27