Maison  >  Article  >  développement back-end  >  C#中获取TimeZoneInfo

C#中获取TimeZoneInfo

黄舟
黄舟original
2017-03-01 10:43:501955parcourir

C#中获取TimeZoneInfo

public TimeZoneInfo TimeZoneInfo
        {
            get
            {
                var timeZoneInfoString = _user.TimeZoneInfoString;
                if (!string.IsNullOrEmpty(timeZoneInfoString))
                {
                    try
                    {
                        return TimeZoneInfo.FindSystemTimeZoneById(timeZoneInfoString);
                    }
                    catch (TimeZoneNotFoundException exception)
                    {
                        LogManager.GetLogger(GetType()).Error(exception);
                    }
                    catch (Exception exception)
                    {
                        LogManager.GetLogger(GetType()).Error(exception);
                    }

                    return TimeZoneInfo.Local;
                }
                else
                {
                    LogManager.GetLogger(GetType()).ErrorFormat("timeZoneInfoString for user {0} is empty", HttpContext.Current.User.Identity.Name);
                    return TimeZoneInfo.Local;
                }
            }
        }


其中,_user.TimeZoneInfoString会存在数据库中

以上就是C#中获取TimeZoneInfo的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn