Exemple #1
0
        /// <summary>
        /// Gets the time from a
        /// <see cref="T:System.DateTime"/>
        /// object in short Metro format.
        /// </summary>
        /// <remarks>
        /// Metro design guidelines normalize strings to lowercase.
        /// </remarks>
        /// <param name="dt">Time information.</param>
        /// <returns>"10:20p" for 10:20 p.m. when en-US.</returns>
        public static string GetSuperShortTime(DateTime dt)
        {
            if (formatInfo_GetSuperShortTime == null)
            {
                lock (lock_GetSuperShortTime)
                {
                    StringBuilder result = new StringBuilder(string.Empty);
                    string        seconds;

                    formatInfo_GetSuperShortTime = (DateTimeFormatInfo)CultureInfo.CurrentCulture.DateTimeFormat.Clone();

                    result.Append(formatInfo_GetSuperShortTime.LongTimePattern);
                    seconds = rxSeconds.Match(result.ToString()).Value;
                    result.Replace(" ", string.Empty);
                    result.Replace(seconds, string.Empty);
                    if (!(DateTimeFormatHelper.IsCurrentCultureJapanese() ||
                          DateTimeFormatHelper.IsCurrentCultureKorean() ||
                          DateTimeFormatHelper.IsCurrentCultureHungarian()))
                    {
                        result.Replace(DoubleMeridiemDesignator, SingleMeridiemDesignator);
                    }

                    formatInfo_GetSuperShortTime.ShortTimePattern = result.ToString();
                }
            }

            return(dt.ToString("t", formatInfo_GetSuperShortTime).ToLowerInvariant());
        }