TekiSreelakshmi
asked on
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.
I want to display Newyork,London,HongKong current time on my aspx page.
How to do?
Plz advise.
Thanks
Sreelakshmi.N.
You should use UTC time as base:
const int newYorkUtcShift = -4;
DateTime newYorkTime = DateTime.UtcNow.AddHours(newYorkUtcShift);
ASKER
I need to consider DST also right ...
-4 or -5 ?
How to check..
Can u send me the complete code...
Thanks,
Sreelakshmi.
-4 or -5 ?
How to check..
Can u send me the complete code...
Thanks,
Sreelakshmi.
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));
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));
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(d ictionary[ "Tokyo"])
GL
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(d
GL
ASKER
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...
If i add -5 to New york time it is showing wrong time ..
Day light saving is not considered in that case...
ASKER
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 ...
problem here is it is not getting refreshed for every second..
So i am trying to use Javascript ...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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(TimeZone Info.Conve rtTimeBySy stemTimeZo neId(DateT ime.UtcNow , centralEuropeTimeZoneId));
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(TimeZone
foreach (TimeZoneInfo zoneInfo in TimeZoneInfo.GetSystemTimeZones())
{
DateTime localTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, zoneInfo);
Console.WriteLine("{2} - {0} ({1})", zoneInfo.Id, zoneInfo.BaseUtcOffset, localTime);
}
Basically it's a free web service which you can call with any latitude/longitude and it returns the local time for that location.