Newyork,London,HongKong current time on my aspx page

Hi,

I want to display Newyork,London,HongKong current time on my aspx page.
How to do?

Plz advise.

Thanks
Sreelakshmi.N.
TekiSreelakshmiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Luis PérezSoftware Architect in .NetCommented:
Check this, hope that helps: http://www.earthtools.org/webservices.htm#timezone

Basically it's a free web service which you can call with any latitude/longitude and it returns the local time for that location.
0
lazyberezovskyCommented:
You should use UTC time as base:
const int newYorkUtcShift = -4;
DateTime newYorkTime = DateTime.UtcNow.AddHours(newYorkUtcShift);

Open in new window

0
TekiSreelakshmiAuthor Commented:
I need to consider DST also right ...
-4 or -5 ?
How to check..
Can u send me the complete code...


Thanks,
Sreelakshmi.
0
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

rajeeshmcaCommented:
hi

DateTime.UtcNow
returns the datetime on the hosting server expressed in Universal Coordinated Time, otherwise known as Greenwich Mean Time.


DateTime.Now
returns the local datetime.

You get the offset in hours and minutes for each of the countries in your list (for e.g. India is 5 hrs 30 mins ahead of GMT) and add it to DateTime.UtcNow to get the local time of the countries.

DateTime localTimeIndia = DateTime.UtcNow.Add(new TimeSpan(5, 30, 0));
0
lazyberezovskyCommented:
You can see time zones here: http://www.worldtimezone.com/
Create mmm.. e.g. dictionary of type <string, int> with city name as key and time zone as value.
Add cities that you need:
dictionary.Add("London", 0);
dictionary.Add("New York", -5);
dictionary.Add("Tokyo", +9);

Then you can quickly get local time for some city (it you have added one)
DateTime.UtcNow.AddHours(dictionary["Tokyo"])

GL
0
TekiSreelakshmiAuthor Commented:
It is not working as u said...
If i add -5 to New york time it is showing wrong time ..
Day light saving is not considered in that case...



0
TekiSreelakshmiAuthor Commented:
DateTime localTimeIndia = DateTime.UtcNow.Add(new TimeSpan(5, 30, 0));
problem here is it is not getting refreshed for every second..

So i am trying to use Javascript ...

0
rajeeshmcaCommented:
u can use the timer in the Ajax extensions for updating the time every second

Refer the following link:

http://ajax.net-tutorials.com/controls/timer-control/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lazyberezovskyCommented:
Ok. You shold use TimeZoneInfo. Code below shows you how to get time zones and current local time for any time zone.

All you need is create mapping from time zone id to city name. E.g. dictionary with key as city name and value as time zone id. After that you simply do this:

string centralEuropeTimeZoneId = "Central Europe Standard Time";
Console.WriteLine(TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, centralEuropeTimeZoneId));
foreach (TimeZoneInfo zoneInfo in TimeZoneInfo.GetSystemTimeZones())
{
    DateTime localTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, zoneInfo);
    Console.WriteLine("{2} - {0} ({1})", zoneInfo.Id, zoneInfo.BaseUtcOffset, localTime);
}

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.