?
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
Medium Priority
?
358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 252 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 248 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Suggested Courses

800 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