.NETGURU
Date/Time display in local time
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngreg' list.


Rangi Keen
I have a date/time field stored in a database and want to display that to
the user in their local time zone. The database stores the date/time in UTC.
Is there a way built into the .NET architecture to do the time zone
conversion based automatically on the server (thus allowing me full access
to the localized date/time formatting)?

Thanks,
Rangi Keen

...........................................................................
Necessity is the plea for every infringement of human freedom.
It is the argument of tyrants; it is the creed of slaves.
-William Pitt, British prime-minister (1759-1806)

Reply to this message...
 
    
Daniel Naumann
Rangi,

Here is a post from an excellent source (on this list) that was posted a few
days ago on the topic.

Daniel.
Old post is below...................

Hi,
This functionality (converting from one arbitrary timezone to another) is not
implemented in the .NET Framework. This is interesting feedback, thanks!
François Liger
.NET Framework International Program Manager

-----Original Message-----
From: Ariel Sagum [mailto:Click here to reveal e-mail address]
Sent: Wednesday, April 17, 2002 7:20 AM
To: aspngreg
Subject: [aspngreg] Timezones

-- Moved from [aspngfreeforall] to [aspngreg] by Yannick Smits
<Click here to reveal e-mail address> --

Hi,

Does anybody know of any function that would convert a certain =
Date/Time value to another timezone?
Or better yet, is this functionality implemented in .Net's localization =
classes?

Any info will be appreciated.

Thanks in advance.
Ariel

-----Original Message-----
From: Rangi Keen [mailto:Click here to reveal e-mail address]
Sent: 29-May-2002 05:35
To: aspngreg
Subject: [aspngreg] Date/Time display in local time

I have a date/time field stored in a database and want to display that to
the user in their local time zone. The database stores the date/time in UTC.
Is there a way built into the .NET architecture to do the time zone
conversion based automatically on the server (thus allowing me full access
to the localized date/time formatting)?

Thanks,
Rangi Keen

...........................................................................
Necessity is the plea for every infringement of human freedom.
It is the argument of tyrants; it is the creed of slaves.
-William Pitt, British prime-minister (1759-1806)

| [aspngreg] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngreg.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
Tom Cabanski
It's not in the .NET framework.

It can be done pretty easily. Put together a server control that
renders a hidden field. Use a bit of Javascript to get the local
timezone offset off the client computer. Stick it in the field. Put a
function on the control that adds the timezone offset to your UTC time
and render it to a label that is also part of the server control.
Walla!

Did one of these for a custom system just recently. Sorry to say that
my agreement with the customer does not allow me to give out the source.

It's fun to do and a great way to learn about server controls if you
don't know them well already. Takes a couple of hours to do if you know
the basics of control creation.

For a more challenging experience try to add this:

If the client does not have Javascript, display the time as UTC.

Just a bit more work but worth it for Internet environments where the
browser configuration is not well-known.

Enjoy!

--------------------------------
Tom Cabanski, President
Objective Advantage, Inc.
http://www.oai.cc
Author of .NET Security coming soon from Manning

-----Original Message-----
From: Rangi Keen [mailto:Click here to reveal e-mail address]
Sent: Wednesday, May 29, 2002 2:35 AM
To: aspngreg
Subject: [aspngreg] Date/Time display in local time

I have a date/time field stored in a database and want to display that
to
the user in their local time zone. The database stores the date/time in
UTC.
Is there a way built into the .NET architecture to do the time zone
conversion based automatically on the server (thus allowing me full
access
to the localized date/time formatting)?

Thanks,
Rangi Keen

........................................................................
...
Necessity is the plea for every infringement of human freedom.
It is the argument of tyrants; it is the creed of slaves.
-William Pitt, British prime-minister (1759-1806)

| [aspngreg] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngreg.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
Francois Liger
Well, actually, what is not in the .NET Framework is the capability to
convert from any time zone to any other. There is support in the .NET
Framework for converting from/to the local time zone and the UTC time
zone.

A typical scenario would be to retrieve the current time using the
DateTime.Now property and then convert it to UTC for storage:
DateTime utc =3D DateTime.Now.ToUniversalTime();

And then displaying (using the local time zone, which could be different
from the one that was originally used to enter the data):
DateTime local =3D utc.ToLocalTime();

Francois Liger
.NET Framework International PM
Click here to reveal e-mail address

-----Original Message-----
From: Tom Cabanski [mailto:Click here to reveal e-mail address]=20
Sent: mardi 28 mai 2002 23:26
To: aspngreg
Subject: [aspngreg] RE: Date/Time display in local time

It's not in the .NET framework.

It can be done pretty easily. Put together a server control that
renders a hidden field. Use a bit of Javascript to get the local
timezone offset off the client computer. Stick it in the field. Put a
function on the control that adds the timezone offset to your UTC time
and render it to a label that is also part of the server control.
Walla!

Did one of these for a custom system just recently. Sorry to say that
my agreement with the customer does not allow me to give out the source.

It's fun to do and a great way to learn about server controls if you
don't know them well already. Takes a couple of hours to do if you know
the basics of control creation.

For a more challenging experience try to add this:

If the client does not have Javascript, display the time as UTC.=20

Just a bit more work but worth it for Internet environments where the
browser configuration is not well-known.

Enjoy!

--------------------------------
Tom Cabanski, President
Objective Advantage, Inc.
http://www.oai.cc
Author of .NET Security coming soon from Manning

-----Original Message-----
From: Rangi Keen [mailto:Click here to reveal e-mail address]=20
Sent: Wednesday, May 29, 2002 2:35 AM
To: aspngreg
Subject: [aspngreg] Date/Time display in local time

I have a date/time field stored in a database and want to display that
to
the user in their local time zone. The database stores the date/time in
UTC.
Is there a way built into the .NET architecture to do the time zone
conversion based automatically on the server (thus allowing me full
access
to the localized date/time formatting)?

Thanks,
Rangi Keen

........................................................................
...
Necessity is the plea for every infringement of human freedom.
It is the argument of tyrants; it is the creed of slaves.
-William Pitt, British prime-minister (1759-1806)

| [aspngreg] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngreg.asp =3D JOIN/QUIT
| http://www.asplists.com/search =3D SEARCH Archives

| [aspngreg] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngreg.asp =3D JOIN/QUIT
| http://www.asplists.com/search =3D SEARCH Archives

Reply to this message...
 
    
Rangi Keen
If you call utc.ToLocalTime() in an ASPX page, does it return the time in
the local server time or the local client time? If it is in the local server
time, is there a way to have it display in the local client time, or would
you need to do this on the client using JavaScript or equivalent?

Thanks,
Rangi Keen
Framework Technologies

...........................................................................
Necessity is the plea for every infringement of human freedom.
It is the argument of tyrants; it is the creed of slaves.
-William Pitt, British prime-minister (1759-1806)

-----Original Message-----
From:     Francois Liger [mailto:Click here to reveal e-mail address]
Sent:    Friday, 31 May, 2002 1:30 PM
To:    aspngreg
Subject:    [aspngreg] RE: Date/Time display in local time

Well, actually, what is not in the .NET Framework is the capability to
convert from any time zone to any other. There is support in the .NET
Framework for converting from/to the local time zone and the UTC time
zone.

A typical scenario would be to retrieve the current time using the
DateTime.Now property and then convert it to UTC for storage:
DateTime utc = DateTime.Now.ToUniversalTime();

And then displaying (using the local time zone, which could be different
from the one that was originally used to enter the data):
DateTime local = utc.ToLocalTime();

Francois Liger
.NET Framework International PM
Click here to reveal e-mail address

-----Original Message-----
From: Tom Cabanski [mailto:Click here to reveal e-mail address]
Sent: mardi 28 mai 2002 23:26
To: aspngreg
Subject: [aspngreg] RE: Date/Time display in local time

It's not in the .NET framework.

It can be done pretty easily. Put together a server control that
renders a hidden field. Use a bit of Javascript to get the local
timezone offset off the client computer. Stick it in the field. Put a
function on the control that adds the timezone offset to your UTC time
and render it to a label that is also part of the server control.
Walla!

Did one of these for a custom system just recently. Sorry to say that
my agreement with the customer does not allow me to give out the source.

It's fun to do and a great way to learn about server controls if you
don't know them well already. Takes a couple of hours to do if you know
the basics of control creation.

For a more challenging experience try to add this:

If the client does not have Javascript, display the time as UTC.

Just a bit more work but worth it for Internet environments where the
browser configuration is not well-known.

Enjoy!

--------------------------------
Tom Cabanski, President
Objective Advantage, Inc.
http://www.oai.cc
Author of .NET Security coming soon from Manning

-----Original Message-----
From: Rangi Keen [mailto:Click here to reveal e-mail address]
Sent: Wednesday, May 29, 2002 2:35 AM
To: aspngreg
Subject: [aspngreg] Date/Time display in local time

I have a date/time field stored in a database and want to display that
to
the user in their local time zone. The database stores the date/time in
UTC.
Is there a way built into the .NET architecture to do the time zone
conversion based automatically on the server (thus allowing me full
access
to the localized date/time formatting)?

Thanks,
Rangi Keen

........................................................................
...
Necessity is the plea for every infringement of human freedom.
It is the argument of tyrants; it is the creed of slaves.
-William Pitt, British prime-minister (1759-1806)

| [aspngreg] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngreg.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngreg] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngreg.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngreg] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngreg.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
Tony Stephenson
Just to add to this..

Remember that DateTime local = utc.ToLocalTime(); will give you the
local time at the SERVER, not the local time at the client.

Life gets complicated if you decide to use a hosting service for your
web site and this is located in a different time zone to the one you are
in when you are happily testing your datetime calculations!

If you want the local time at the client you have to get the timezone
offset at the client, then convert the utc time using this offset.

Tony Stephenson
Email:    Click here to reveal e-mail address

-----Original Message-----
From: Francois Liger [mailto:Click here to reveal e-mail address]
Sent: Saturday, 1 June 2002 3:30 AM
To: aspngreg
Subject: [aspngreg] RE: Date/Time display in local time

Well, actually, what is not in the .NET Framework is the capability to
convert from any time zone to any other. There is support in the .NET
Framework for converting from/to the local time zone and the UTC time
zone.

A typical scenario would be to retrieve the current time using the
DateTime.Now property and then convert it to UTC for storage:
DateTime utc = DateTime.Now.ToUniversalTime();

And then displaying (using the local time zone, which could be different
from the one that was originally used to enter the data):
DateTime local = utc.ToLocalTime();

Francois Liger
.NET Framework International PM
Click here to reveal e-mail address

-----Original Message-----
From: Tom Cabanski [mailto:Click here to reveal e-mail address]
Sent: mardi 28 mai 2002 23:26
To: aspngreg
Subject: [aspngreg] RE: Date/Time display in local time

It's not in the .NET framework.

It can be done pretty easily. Put together a server control that
renders a hidden field. Use a bit of Javascript to get the local
timezone offset off the client computer. Stick it in the field. Put a
function on the control that adds the timezone offset to your UTC time
and render it to a label that is also part of the server control.
Walla!

Did one of these for a custom system just recently. Sorry to say that
my agreement with the customer does not allow me to give out the source.

It's fun to do and a great way to learn about server controls if you
don't know them well already. Takes a couple of hours to do if you know
the basics of control creation.

For a more challenging experience try to add this:

If the client does not have Javascript, display the time as UTC.

Just a bit more work but worth it for Internet environments where the
browser configuration is not well-known.

Enjoy!

--------------------------------
Tom Cabanski, President
Objective Advantage, Inc.
http://www.oai.cc
Author of .NET Security coming soon from Manning

-----Original Message-----
From: Rangi Keen [mailto:Click here to reveal e-mail address]
Sent: Wednesday, May 29, 2002 2:35 AM
To: aspngreg
Subject: [aspngreg] Date/Time display in local time

I have a date/time field stored in a database and want to display that
to
the user in their local time zone. The database stores the date/time in
UTC.
Is there a way built into the .NET architecture to do the time zone
conversion based automatically on the server (thus allowing me full
access
to the localized date/time formatting)?

Thanks,
Rangi Keen

........................................................................
...
Necessity is the plea for every infringement of human freedom.
It is the argument of tyrants; it is the creed of slaves.
-William Pitt, British prime-minister (1759-1806)

| [aspngreg] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngreg.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngreg] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngreg.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngreg] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngreg.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
 
System.DateTime




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification