• Asp.net 时间操作基类(短日期,长日期,时间差)


    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    namespace EC
    {
        /// <summary>
        /// 时间操作函数
        /// </summary>
        public class TimeObject
        {
            /// <summary>
            /// 时间差
            /// </summary>
            /// <param name="starttime">开始时间</param>
            /// <param name="endtime">结束时间</param>
            /// <returns></returns>
            public static string GetTimeSpan(DateTime starttime, DateTime endtime)
            {
                TimeSpan ts = endtime - starttime;
                return string.Format("{0}时{1}分{2}秒{3}毫秒", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
            }

            /// <summary>
            /// 转称为月-日:09-12
            /// </summary>
            /// <param name="d">日期</param>
            /// <returns></returns>
            public static string ToDateMonthDay(DateTime d)
            {
                return d.ToString("MM-dd");
            }
            /// <summary>
            /// 转换为年月日:2006-09-12
            /// </summary>
            /// <param name="d"></param>
            /// <returns></returns>
            public static string ToDateString(DateTime d)
            {
                return d.ToString("yyyy-MM-dd");
            }
            /// <summary>
            /// 转换为:小时:分:秒 00:29:58
            /// </summary>
            /// <param name="t"></param>
            /// <returns></returns>
            public static string ToTimeString(DateTime t)
            {
                return t.ToString("HH:mm:ss");
            }
            /// <summary>
            /// 转换为长时间:2006-09-12 00:30:57
            /// </summary>
            /// <param name="dt"></param>
            /// <returns></returns>
            public static string ToDateTimeString(DateTime dt)
            {
                return dt.ToString("yyyy-MM-dd HH:mm:ss");
            }    

       
        }

    }

  • 相关阅读:
    hdoj 6023 Automatic Judge
    hdoj 1170 Balloon Comes!
    初识vim操作和配置
    POJ 1611 The Suspects (并查集)
    HDU 1232 畅通工程 (并查集)
    计蒜客--两数之和
    计蒜客--爬楼梯 (动态规划)
    计蒜客--单独的数字 (位运算)
    计蒜客--最后一个单词的长度
    计蒜客-- 奇怪的国家 (位运算)
  • 原文地址:https://www.cnblogs.com/zhangchenliang/p/736660.html
Copyright © 2020-2023  润新知