How to display DateTime with an abbreviated Time Zone?

前端 未结 8 986
长情又很酷
长情又很酷 2020-12-08 19:02

I am aware of the System.TimeZone class as well as the many uses of the DateTime.ToString() method. What I haven\'t been able to find is a way to convert a DateTime to a st

8条回答
  •  旧时难觅i
    2020-12-08 19:20

    Here's my quick hack method I just made to work around this.

    public static String TimeZoneName(DateTime dt)
    {
        String sName = TimeZone.CurrentTimeZone.IsDaylightSavingTime(dt) 
            ? TimeZone.CurrentTimeZone.DaylightName 
            : TimeZone.CurrentTimeZone.StandardName;
    
        String sNewName = "";
        String[] sSplit = sName.Split(new char[]{' '});
        foreach (String s in sSplit)
            if (s.Length >= 1)
                sNewName += s.Substring(0, 1);
    
        return sNewName;
    }
    

提交回复
热议问题