日本财政年度取得(c#,vb.net)

vb.net:

  '----------------------------------------------------------------
    '-  @(f)
    '-
    '-  機    能: 日本財政年度取得
    '-
    '-  返    値:    日本財政年度
    '-
    '-  引    数: 日付
    '-
    '-  機能説明: 日本財政年度取得
    '-
    '----------------------------------------------------------------
    Public Function GetJpNendo(ByVal dtValue As Date) As String
        Dim strNendo As String

        Try
            strNendo = dtValue.ToString().Substring(0, 4)
            Dim dtTemp As Date = CDate(strNendo & "/03/31")
            If Date.Compare(dtValue, dtTemp) < 0 OrElse Date.Compare(dtValue, dtTemp) = 0 Then
                strNendo = CStr(CInt(strNendo) - 1)
            End If
        Catch ex As Exception
        End Try
        Return strNendo
    End Function

c#:

    /// <summary>
        /// 日本財政年度取得
        /// </summary>
        /// <param name="dtValue">日付</param>
        /// <returns>日本財政年度</returns>
        private string GetJPNendo(DateTime dtValue)
        {
            string strNendo = string.Empty;
            try
            {
                strNendo = dtValue.ToString().Substring(0, 4);
                DateTime dtTemp = DateTime.Parse(strNendo + "/03/31");
                if (dtValue <= dtTemp)
                {
                    strNendo = Convert.ToString(Convert.ToInt32(strNendo) - 1);
                }
            }
            catch
            {
            }
            return strNendo;
        }

posted on 2011-09-09 11:14  念念啊  阅读(292)  评论(0编辑  收藏  举报