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
347 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

856 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