Last post Oct 31, 2011 07:58 AM by cts-mgraham
Sep 21, 2011 05:19 AM|sanjuv|LINK
As per Rss spec, in order to show time in GMT format, I have formatted the date as per http://forums.asp.net/t/1509953.aspx/1
But the time is incorrect when displayed in Rss after getting date from database.
Say if I have a db date as 9/20/2011 5:56:57 PM. Then when I do the conversion as present in the above link, the date get's converted into
Tue, 20 Sep 2011 17:56:57 GMT. But when this is displayed in Rss, it shows as Tuesday, September 20, 2011 11:26 PM.
I did a conversion of the same time from GMT to IST online and it showed whe same as what i told above. So I thought of first converting the date from db to GMT using
TimeZoneInfo timeZoneIST = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
TimeZoneInfo timeZoneGMT = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
DateTime GMTtime = TimeZoneInfo.ConvertTime(submitted_on, timeZoneIST, timeZoneGMT);
which only does the formatting . But this gave the date and time as
Tuesday, September 20, 2011 6:56 PM in Rss feed, which is an hour's difference to the expected time of 5:56 PM.
Any ideas? Of course, I could simply do submitted_on.AddHours(-1) , and the correct time would come after conversion. But is there any other correct way? What about daylight savings?
Sep 21, 2011 07:55 AM|bbcompent1|LINK
I suspect it may be the regional settings of your server that could be floundering the time. It looks like its doing an offset of +5 hrs so you may need to subtract five hours to get it correct.
Sep 21, 2011 08:05 AM|sanjuv|LINK
I too thought that it could be regional settings of the server. But it was then that I realised, that I am developing this on my sytem and it is running in the local IIS. I am just clicking the RUN button of visual studio and it is showing the feed with
changed date. So what is exactly happening?
Sep 21, 2011 08:11 AM|bbcompent1|LINK
I think it has somethign to do with this line here:
What you may need to do is take that and do a dateadd(hours, -5) or similar since it seems to be taking the greenwhich median time no matter where you are. Once you convert the value to string, you can't really change the datetime value because it is a text
string, not a datetime value. :) so try rewriting it like this:
Sep 22, 2011 09:47 PM|Decker Dong - MSFT|LINK
What about using this:
Sep 23, 2011 03:35 AM|sanjuv|LINK
I will surely try that out and post the result here. I have no access to my development machine for a few days. But I would like to mention that I did try to convert first into UTC and then into GMT format. I did not help. But will try this out in a few
days and post the results here. thanks...
Sep 25, 2011 11:42 PM|sanjuv|LINK
Decker Dong - MSFT
What about using this:
Tried that. Didn't work out. Now I am just subtracting by a few hours and displaying it. NO idea about how to do for daylight savings.
Oct 31, 2011 07:58 AM|cts-mgraham|LINK
Have you tried using TimeZoneInfo to see what timezone the server is on? This site has some samples: