Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP:Calendar but ISP server is in another time zone

Status
Not open for further replies.

markdmac

MIS
Dec 20, 2003
12,340
US
I am currently using an ASP Calendar on my web page. I have realized that my web site is sitting on a server in another time zone and the day of the week is ahead by several hours which can make the selected day be off by a day. Is there a way to control what date the calendar control uses as "today" so I can subtract the necessary hours with date manipulation? Looking at the properties of the control I don't see anything for time zone.

 
I was able to resolve this with the following added to my Page_Load

Code:
	Calendar1.TodaysDate = DateAdd("h",-7,Now)

Hope this helps someone else that may run into the same problem. I isolated the date & time that the server was in with a simple page with a label that I set to "Now". That allowed me to compare to my local time to see the difference in hours.

I then just added the difference in hours (negative for me) and set the calandar "TodaysDate" and that resolved the time difference.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
this method only works if the ISP doesn't change the location of the server or you don't switch ISPs. I would recommend researching the System.TimeZone class or Globalization for asp.net.

They may provide a way to set the correct date/time without hardcoding to the server.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
An excellent suggestion Jason, thank you. I found a good example of using it here:
I will add this to my to do list as I agree with you, it is a better (more universal) soloution.

Looks like I will want to convert the local time to UTC first, then do my DateAdd to that date/time. The following shows converting to UTC.

Lucky for me Arizona does not do daylight savings time so I don't need to be concerned with that.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
So here is what I came up with:

Code:
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="Microsoft.VisualBasic" %>

<%@ OutputCache Duration="3600" VaryByParam="none" %>
<script language="VB" runat=server>

  Sub Page_Load(sender As Object, e As EventArgs)
    ' Get the local time zone and the current local time and year.
      Dim localZone As TimeZone = TimeZone.CurrentTimeZone
      Dim currentDate As DateTime = DateTime.Now
     
    ' Get the current Coordinated Universal Time (UTC) 
      Dim currentUTC As DateTime = _
      localZone.ToUniversalTime( currentDate )
               

		label1.text = "Server Date:" & currentDate
		label2.text = "UTC:" & currentUTC 
		label3.text = "AZ Time:" & DateAdd("h",-7,currentUTC)
  

  End Sub

</script>



<html dir="ltr" xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]

<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
</head>

<body>

<form id="form1" runat="server">
<asp:Label runat="server" id="Label1"></asp:Label><br />
<asp:Label runat="server" id="Label2"></asp:Label><br />
<asp:Label runat="server" id="Label3"></asp:Label><br />
<div style="font-family: Arial, 'Microsoft Sans Serif';font-size: 10pt;">

</div>
</form>

</body>

</html>

As it turns out my ISP is using UTC time for the servers so I really don't need to change what I was doing.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Hi mate

Not sure if you got it sorted out yet, but I had this same problem. Easiest way to fix it is to add the following to your web.config file

Code:
<configuration>
  <system.web>
   <globalization
     fileEncoding="utf-8"
     requestEncoding="utf-8"
     culture="en-GB"
     uiCulture="en-GB"
  />
</system.web>
</configuration>

Obviously replace the "en-GB" with your local culture and replace uiCulture with your local culture
 
thanks ozroo. I did solve it but this is a nice solution as well.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top