Extensions/TimeSpanExtensions.cs

(完整代码) 1KB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ComLib.Extensions
{
    /// <summary>
    /// This static class provides several common extensions for TimeSpan.
    /// </summary>
    public static class TimeSpanExtensions
    {
        /// <summary>
        /// Determines whether [is midnight exactly] [the specified t].
        /// </summary>
        /// <param name="t">The t.</param>
        /// <returns>
        /// 	<c>true</c> if [is midnight exactly] [the specified t]; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsMidnightExactly(this TimeSpan t)
        {
            return t.Hours == 0 && t.Minutes == 0 && t.Seconds == 0;
        }


        /// <summary>
        /// Get simple time format
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static string ToMilitaryString(this TimeSpan t)
        {
            string time = t.Hours + ":" + t.Minutes + ":" + t.Seconds;

            if (t.Days > 0)
                time = t.Days + "dys " + time;

            return time;
        }


        /// <summary>
        /// Returns an integer representing mii
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static int ToMilitaryInt(this TimeSpan t)
        {
            int time = t.Hours * 100;
            time += t.Minutes;
            return time;
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。