将UTC时间跨度转换为c#中的IST时间跨度

本文关键字:时间跨度 中的 IST 转换 UTC | 更新日期: 2023-09-27 18:09:09

我在UTC时区的服务器上的TimeSpan中存储了一天中的各种时间。现在我想检索IST区域中的记录。在我的服务器上,数据是HH:mm:ss格式,我想让它以IST区域的相同格式返回。我可以使用下面的代码将DateTime转换为TimeSpan,但我不能从TimeSpan转换为TimeSpan。

 DateTime timeUtc = DateTime.UtcNow;
  TimeZoneInfo istZone = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
  DateTime istTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, istZone);
  return string.Format("The date and time are {0}.", istTime.TimeOfDay.ToString().Substring(0, 6));

将UTC时间跨度转换为c#中的IST时间跨度

试试这个

DateTime utcdate = DateTime.ParseExact("6/15/2014 12:00:00 AM", "M/dd/yyyy 
                                       h:mm:ss tt",CultureInfo.InvariantCulture);
var istdate = TimeZoneInfo.ConvertTimeFromUtc(utcdate,
TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"));