无法将时间转换为当地时区,即IST

时间:2017-03-06 18:15:14

标签: c# datetime

我得到这样的时间

  2017-03-06T12:51:33.481Z

desired output time 



 3/6/2017, 6:21:33 PM

我得到这样的时间

3/6/2017 5:56:33 AM

数据类型是字符串

public string UpdatedTime { get; set; }

     string updtime = bin.timestamp;//03/06/2017 12:51:33
     string ISTTime = Convert.ToDateTime(updtime).ToString("M/d/yyyy, h:mm:ss tt", CultureInfo.InvariantCulture);//3/6/2017, 6:21:33 PM
                binModel.UpdatedTime = ISTTime;

1 个答案:

答案 0 :(得分:0)

此代码对我有用:

        string updtime = "03/06/2017 12:51:33";
        string ISTTime = Convert.ToDateTime(updtime).ToString("M/d/yyyy, h:mm:ss tt", CultureInfo.InvariantCulture);//3/6/2017, 6:21:33 PM
        var ISTDate = TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(ISTTime), TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"));