将UTC时间转换为IST时间

时间:2013-10-28 12:58:18

标签: .net vb.net

我想将UTC时间转换为IST时间。 但我得到的时间格式低于格式。 时间= 111524.000 请告诉我如何将上述格式转换为IST格式

我尝试了以下代码,但它并不适合我

Dim str As String = "111524.000"
Dim formats As String() = New String() {"HH:mm:ss"}
Dim dt As DateTime = DateTime.ParseExact(str, formats, System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.AdjuToUniversal)
Dim strTime As String = dt.ToShortTimeString()

我希望时间为11:15:24

1 个答案:

答案 0 :(得分:1)

    Dim str As String = "111524.000" 'UTC Time
    Dim formats As String = "HHmmss.fff"
    Dim dt As DateTime = DateTime.ParseExact(str, formats, System.Globalization.CultureInfo.InvariantCulture, Globalization.DateTimeStyles.AssumeUniversal Or Globalization.DateTimeStyles.AdjustToUniversal)
    Dim strTime As String = dt.ToString

    Debug.WriteLine(dt.ToString & " " & dt.Kind.ToString)

    Dim IST As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")
    Dim ISTdt As DateTime = TimeZoneInfo.ConvertTime(dt, IST)

    Debug.WriteLine(ISTdt.ToString & " " & ISTdt.Kind.ToString)