schangxiang@126.com
2025-09-19 fc752b66a7976188c4edd5e3fb7ca6bb2822e441
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
namespace wcftest
{
    /// <summary>
    /// 日期处理类
    /// </summary>
    public class DateTimeHelper
    {
        /// <summary>
        /// 转换日期格式为字符串
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static string ConvertToString(DateTime? dt)
        {
            if (dt == null)
            {
                return string.Empty;
            }
            return Convert.ToDateTime(dt).ToString("yyyy-MM-dd HH:mm:ss");
        }
 
        /// <summary>
        /// 转换日期格式为字符串
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static string ConvertToStringForOnlyShowTime(DateTime? dt)
        {
            if (dt == null)
            {
                return string.Empty;
            }
            return Convert.ToDateTime(dt).ToString("HH:mm:ss");
        }
    }
}