如何实现DateTime

时间:2014-05-14 04:27:14

标签: c#

任何人都可以告诉我如何在此代码上实现DateTime?试图谷歌,但仍然混淆这个代码。

     public double CalcLastCouponDate(DateTime dtmBaseDate, DateTime dtmLastDate, int intCouponTermMonths, int intFixedCouponDay, string strOddLastCouponType)
    {
        int i = 0;
        DateTime dtmLastCoupon;
        {
            if (strOddLastCouponType == "S")
            {
                return dtmLastCoupon = DateAdd("M", -intCouponTermMonths, dtmLastCoupon); // How to convert DateAdd to C#
            }
            else
            {
                return dtmLastCoupon = DateAdd("M", -2 * intCouponTermMonths, dtmLastCoupon); // How to convert DateAdd to C#
            }
        }
    }

    public bool IsEndDayofMonth(DateTime DateIn)
    {
        int intLastDay = 0; 
        bool IsEndDay = false;

        intLastDay = CalcEndDayofMonth(Year(DateIn), Month(DateIn)); // Convert Year, Month to C#
        if (intLastDay == Day(DateIn)) // Convert Day to C#
        {
        IsEndDay = true;
        }
        else
        {
            IsEndDay = false;
        }
        return IsEndDay;

2 个答案:

答案 0 :(得分:1)

假设DateAdd具有正常的语义,它可能看起来像这样:

public DateTime CalcLastCouponDate(DateTime dtmBaseDate, DateTime dtmLastDate, int intCouponTermMonths, int intFixedCouponDay, string strOddLastCouponType)
{
    return (strOddLastCouponType == "S") ?
        dtmLastDate.AddMonths(-intCouponTermMonths) :
        dtmLastDate.AddMonths(-2 * intCouponTermMonths);
}

public bool IsLastDayOfMonth(DateTime dateIn)
{
    return dateIn.Day == DateTime.DaysInMonth(dateIn.Year, dateIn.Month);
}

答案 1 :(得分:0)

你可以清楚地了解你想要达到的目标。

查看以下链接我认为您可能会发现自己需要。

Custom date time formats

DateTime methods