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
341 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Uploading files to the web server has become common part of almost any kind of web application. People use different technologies to solve this, but regardless of the technology used, it is always useful to have some kind of progress indicator shown…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

757 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

22 Experts available now in Live!

Get 1:1 Help Now