Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Current Date and Time of a Specific Country

i need to get Turkey's (Istanbul) date and time from a server in another country. So i can use it in my asp.net project and add it to my sql server database. Can you help me please ?

like image 998
CePur Avatar asked May 09 '15 21:05

CePur


2 Answers

Try this:

var info = TimeZoneInfo.FindSystemTimeZoneById("Turkey Standard Time");
DateTimeOffset localServerTime = DateTimeOffset.Now;
DateTimeOffset localTime= TimeZoneInfo.ConvertTime(localServerTime, info);
like image 90
freethinker Avatar answered Oct 02 '22 23:10

freethinker


You can get Turkey time this way:

 // Get time in local time zone 
 DateTime thisTime = DateTime.Now;
 Console.WriteLine("Time in {0} zone: {1}",
        TimeZoneInfo.Local.IsDaylightSavingTime(thisTime) ?
        TimeZoneInfo.Local.DaylightName : TimeZoneInfo.Local.StandardName, thisTime);
 Console.WriteLine("   UTC Time: {0}",
        TimeZoneInfo.ConvertTimeToUtc(thisTime, TimeZoneInfo.Local));

 // Get GTB Standard Time zone - (GMT+02:00) Athens, Istanbul, Minsk
 TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById("GTB Standard Time");
 DateTime tstTime = TimeZoneInfo.ConvertTime(thisTime, TimeZoneInfo.Local, tst);      
 Console.WriteLine("Time in {0} zone: {1}",
        tst.IsDaylightSavingTime(tstTime) ?
        tst.DaylightName : tst.StandardName, tstTime);
 Console.WriteLine("   UTC Time: {0}",
        TimeZoneInfo.ConvertTimeToUtc(tstTime, tst));

For further information, please see:
TimeZoneInfo.FindSystemTimeZoneById Method
Microsoft Time Zone Index Values

like image 24
Maciej Los Avatar answered Sep 29 '22 23:09

Maciej Los