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 ?
Try this:
var info = TimeZoneInfo.FindSystemTimeZoneById("Turkey Standard Time");
DateTimeOffset localServerTime = DateTimeOffset.Now;
DateTimeOffset localTime= TimeZoneInfo.ConvertTime(localServerTime, info);
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With