我需要从另一个国家/地区的服务器获取土耳其(伊斯坦布尔)的日期和时间。所以我可以在我的asp.net项目中使用它并将其添加到我的sql server数据库中。你能帮帮我吗?
答案 0 :(得分:3)
试试这个:
var info = TimeZoneInfo.FindSystemTimeZoneById("Turkey Standard Time");
DateTimeOffset localServerTime = DateTimeOffset.Now;
DateTimeOffset localTime= TimeZoneInfo.ConvertTime(localServerTime, info);
答案 1 :(得分:2)
你可以通过这种方式获得土耳其时间:
// 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));
有关详细信息,请参阅:
TimeZoneInfo.FindSystemTimeZoneById Method
Microsoft Time Zone Index Values