Solved

ASP.NET 2.0 - DateTime.Now How do I adjust to London time when host server is in California?

Posted on 2006-11-12
9
344 Views
Last Modified: 2012-05-05
Hello,

I have the following code in my website:

<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        dateLabel.Text = DateTime.Now.ToString("dddd, dd MMMM yyyy")

      End Sub
</script>

Having recently transferred hosts to Lunarpages who are based in California (who are GMT/UTC - 08:00 hours), the date now displayed on my website is incorrect.

How do I adjust my code so the day changes at midnight UK time?

Many thanks

Karen
0
Comment
Question by:Hels_UK
  • 3
  • 2
9 Comments
 
LVL 12

Expert Comment

by:UnexplainedWays
ID: 17927768

            adjustment = 0;

            if (Running on Lunarpages) //Do a check to see if its http://yourwebsite.com or if its http://localhost for when your working @ home)
            {
                adjustment = X;
            }

            DateTime now = DateTime.Now;
            now.AddHours(adjustment);

0
 
LVL 12

Accepted Solution

by:
UnexplainedWays earned 63 total points
ID: 17927774
You'll need to find out the time currently and what the time of the server is, and then do the math and replace the X with the number.

Check out http://msdn2.microsoft.com/en-us/library/system.datetime_members.aspx

----
AddDays         Adds the specified number of days to the value of this instance.
AddHours       Adds the specified number of hours to the value of this instance.
AddMilliseconds       Adds the specified number of milliseconds to the value of this instance.
AddMinutes       Adds the specified number of minutes to the value of this instance.
AddMonths       Adds the specified number of months to the value of this instance.
AddSeconds       Adds the specified number of seconds to the value of this instance.
AddTicks       Adds the specified number of ticks to the value of this instance.
AddYears       Adds the specified number of years to the value of this instance.
----
0
 
LVL 5

Assisted Solution

by:prajapati84
prajapati84 earned 62 total points
ID: 17928737
Try this one...

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     Dim culture As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-GB")
     dateLabel.Text = DateTime.Parse(DateTime.Now.ToString("dddd, dd MMMM yyyy"), culture, System.Globalization.DateTimeStyles.NoCurrentDateDefault)
End Sub

Regards,
Mukesh
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 5

Expert Comment

by:prajapati84
ID: 17928842
Or You can add hours or subtract hours of the difference between US time and UK time to ur textbox,

dim uktime as datetime
uktime = DateTime.Now
dim differenceHours as integer
'differenceHours = urdifference
uktime= uktime.AddHours(differenceHours)
dateLabel.Text = Convert.ToDateTime(uktime).ToString("dddd, dd MMMM yyyy")

Regards,
Mukesh
0
 

Author Comment

by:Hels_UK
ID: 18020894
Hi,

Thanks for the response - I'm in the process of trying out the option from prajapati84 - I'll post my final answer here soon.

Hels
0
 
LVL 12

Expert Comment

by:UnexplainedWays
ID: 18189820
Any reason why mine didn't work?  It even used the same method calls.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now