 |
|
 |
Hello,
I am very new to developing websites for different timezones therefore i have never used this.
Would you be able to tell me how you would convert the code from default.aspx into vb.
Thanks
|
|
|
|
 |
|
 |
I am not sure what exactly you are trying to do.
If you use desktop vb app you don't need this because you should be able to read timezone info from your computer.
If you use web app with vb.net you do it exactly same way as shown.
|
|
|
|
 |
|
 |
imatureStudent wrote: Would you be able to tell me how you would convert the code from default.aspx into vb.
Check this blog post .NET Code Conversion[^]
|
|
|
|
 |
|
 |
This is exactly what I needed for for an app I'm working on. I wanted to get the users' time zones without burdening them with difficult questions like "What time zone are you in?". Great Post. Bookmarked it.
|
|
|
|
 |
|
|
 |
|
 |
I am unable to run this application due to authentication.
can u help me ?
|
|
|
|
 |
|
 |
i am facing the same issue.... Please let me know how to go about it....
|
|
|
|
 |
|
 |
I am in the US (during daylight savings time. ) I downloaded the project and ran it. It worked fine. It shows that I am in central Time. Then I noticed the posts and made the changes. Afterwards the page showed that I was in eastern time, which is wrong. I do know that my pc automatically handles daylight savings time (the Windows check box in the date and time settings...) I don't know if that matters. Are the script changes in the post valid?
|
|
|
|
 |
|
 |
I had the same issue. Perhaps it was due to integer rounding somewhere? I gave a solution in this post: http://www.codeproject.com/useritems/Remote_Time_Zone.asp?msg=2340027#xx2340027xx
Kirby Zhang
|
|
|
|
 |
|
 |
Hi,
I think there is a problem with the daylight saving time.
The line:
DateTime resultDateTime = utcDateTime.AddHours(profile.hoursDiffStdTime + 1);
always sum "1" to the time offset, but this is correct only when Daylight saving time is active (summer). The correct solution is to calculate the correct time offset on the client, where your code fails because you do not care about the day of the year.
This shoud be ok:
var rightNow = new Date();
var date1 = new Date(rightNow.getFullYear(), rightNow.getMonth(), rightNow.getDay(), 0, 0, 0, 0);
var temp = date1.toGMTString();
var date2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
var hoursDiffStdTime = (date1 - date2) / (1000 * 60 * 60);
..
With this the hoursDiffStdTime is the correct time offset, because date1 is calculated with the correct day of the year.
So, the "+1" is not more needed:
DateTime resultDateTime = utcDateTime.AddHours(profile.hoursDiffStdTime);
chrjs
|
|
|
|
 |
|
 |
Hi Christian,
Thanks you so much, this is very good point. The code was not correctly handled daylight savings.
But the way you proposing to change the code is not working for me.
The correct fix would be to add bool property to the profile indicatiing if user in daylite saving time zone.
So here are the changes:
1)web.config:
2) The best javascript solution for the daylight saving i found here:
http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256CFB006C45F7[^]
So based on that javascript changed to this:
function GetLocalTimeOffset()
{
var rightNow = new Date();
var date1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);
var date2 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0);
var temp = date1.toGMTString();
var date3 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
var temp = date2.toGMTString();
var date4 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
var hoursDiffStdTime = (date1 - date3) / (1000 * 60 * 60);
var hoursDiffDaylightTime = (date2 - date4) / (1000 * 60 * 60);
if (hoursDiffDaylightTime == hoursDiffStdTime) {
//Daylight Saving Time is NOT observed here.
createCookie("daylightSavingTime", "false", 0);
} else {
//Daylight Saving Time is observed here.
createCookie("daylightSavingTime", "true", 0);
}
createCookie("hoursDiffStdTime", hoursDiffStdTime, 0);
//alert(readCookie("hoursDiffStdTime"));
}
3)To set daylight savings on the server we will add this line:
Profile.daylightSavingTime= bool.Parse(Request.Cookies["daylightSavingTime"].Value );
4)Manager class:
instead of: DateTime resultDateTime = utcDateTime.AddHours(profile.hoursDiffStdTime + 1);
there will be: resultDateTime = utcDateTime.AddHours(profile.hoursDiffStdTime + (profile.daylightSavingTime?1 ));
Please let me know if anyone want me to repost updated code.
Thanks,
Dmitry
|
|
|
|
 |
|
 |
Hi Dmitry,
it is strange that my code does not work for you (i'm talking about the client side code).
Maybe we do not want the same think from client.
Look at this sample html page:
<html>
<head>
<script language="javascript">
function showTimezone()
{
var rightNow = new Date();
var date1 = new Date(rightNow.getFullYear(), rightNow.getMonth(), rightNow.getDay(), 0, 0, 0, 0);
var temp = date1.toGMTString();
var date2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
var hoursDiffStdTime = (date1 - date2) / (1000 * 60 * 60);
alert(hoursDiffStdTime);
}
</script>
</head>
<body önload="showTimezone()">
</body>
</html>
The code make the difference, in hours, from the current client time to the current GMT time. This is all you need to convert on the server from globaltime to client local time, obviously if you start from a GMT time.
On my machine i'm in +1 time zone (Italy), now we are in daytlight saving time, so this page print "2", that is the correct offset from GMT.
Later, in november for example, there isn't daylight saving time, and my page correctly print "1" as time offset.
On server side, this number is all that you need:
clientTime = globalGMTTime.AddHours(cookievalue);
Let me know if I misunderstand something!
|
|
|
|
 |
|
 |
Hi Christian,
Your javascript works fine.
Thank you so much,
Dmitry
|
|
|
|
 |
|
 |
Thanks to you, I'm using your javascript (revised for daylight saving time) in my site Quick Bookmarks.
Cheers,
chrjs.
|
|
|
|
 |
|
 |
Using Christian's code it was one hour too fast here in Pacific Time, daylight savings off. It had this problem on two browsers. Perhaps there was integer truncation somewhere?
This is the version I'm using which works for me.
var rightNow = new Date();
var temp = rightNow.toGMTString();
var gmtNow = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
// the x= round(x*2)/2 is used for rounding time zone with half hour offsets
var hoursDiffStdTime = Math.round((rightNow - gmtNow) / (1000 * 60 * 60) * 2) / 2;
I'm using your code for a scheduling gadget on my front page: http://www.battleballgame.net
Kirby Zhang
|
|
|
|
 |
|
|
 |
|
 |
Thanks. That is interesting and very useful article. But this article shows the way to use DateTime Values according to the remote time zone in your ASP.NET applications, while that article is very generic (but still usefull)
|
|
|
|
 |
|
 |
I have found the DST code very useful and used it for a world clock cisco Xml IP phone service for my company. (Xslt, C# & ASP.NET)
|
|
|
|
 |