且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#返回以数字日期编号为日期函数

更新时间:2022-06-30 11:36:02

/// <summary>
/// 返回以数字日期编号为日期函数
/// </summary>    
/// <returns>日期编号</returns>
public DateTime GetCodeToDate(string MyDateCode)
{
    try // 正常运行
    {
        String strYear = MyDateCode.Substring(0, 4);
        String strMonth = MyDateCode.Substring(4, 2);
        String strDay = MyDateCode.Substring(6, 2);
        // 返回日期
        return Convert.ToDateTime(strYear.ToString() + "-" + strMonth.ToString() + "-" + strDay.ToString());
    }
    catch (System.Exception Exp) // 异常处理
    {
        // 异常信息
        System.Diagnostics.Debug.Write(Exp.Message.ToString());
        // 返回日期
        return DateTime.Today;
    }
}

我有几张阿里云幸运券分享给你,用券购买或者升级阿里云相应产品会有特惠惊喜哦!把想要买的产品的幸运券都领走吧!快下手,马上就要抢光了。
https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=6evata1e&utm_source=6evata1e