2011-10-14 2 views
1

NAnt에서 현재 월 이름을 얻으려면 어떻게해야합니까?NAnt의 월 이름

다음과 같은 작업을 사용하여 사이트가 만들어진 날짜/시간을 보여주는 사이트 레이블을 업데이트합니다. 그러나 기계 형식에 따라 날짜가 아닌 특정 형식으로 날짜가 필요합니다.

<xmlpoke file="\\path\to\server\folder\Web.config" 
    xpath="/configuration/appSettings/add[@key = 'SiteLabel']/@value" 
    value="[SQLServer].[SQLDatabase] - ${datetime::to-string(datetime::now())}" /> 

필요한 형식은 "MMM DD, YYYY"입니다. NAnt는 형식을 지정할 수있는 것처럼 보이지 않지만 NAnt 함수를 사용하여 날짜의 개별 부분을 가져올 수 있습니다.

NAnt 함수를 사용하여 이번 달의 이름을 얻을 수있는 방법이 있습니까?
${datetime::get-month(datetime::now())}은 이름이 아닌 월 번호 만 반환합니다.

답변

1

그것은 우아한 수 있지만 수 없습니다 당신의 수 같은 것을 :

<target name="GetMonth"> 

    <property name="today.month" value="${datetime::get-month(datetime::now())}" /> 

    <if test="${today.month=='1'}"> 
     <property name="month" value="Janurary" /> 
    </if> 
    <if test="${today.month=='2'}"> 
     <property name="month" value="Feb" /> 
    </if> 
    <if test="${today.month=='3'}"> 
     <property name="month" value="March" /> 
    </if> 
    <if test="${today.month=='4'}"> 
     <property name="month" value="April" /> 
    </if> 
    <if test="${today.month=='5'}"> 
     <property name="month" value="May" /> 
    </if> 
    <if test="${today.month=='6'}"> 
     <property name="month" value="June" /> 
    </if> 
    <if test="${today.month=='7'}"> 
     <property name="month" value="July" /> 
    </if> 
    <if test="${today.month=='8'}"> 
     <property name="month" value="Aug" /> 
    </if> 
    <if test="${today.month=='9'}"> 
     <property name="month" value="Sept" /> 
    </if> 
    <if test="${today.month=='10'}"> 
     <property name="month" value="Oct" /> 
    </if> 
    <if test="${today.month=='11'}"> 
     <property name="month" value="Nov" /> 
    </if> 
    <if test="${today.month=='12'}"> 
     <property name="month" value="Dec" /> 
    </if> 

    <echo>${month}</echo> 
</target> 
+0

감사합니다, 매력처럼 작동하는'Choose' 비록 ->'문은 조금 더 예뻐이다 When' . –

3

더 우아한 방법 :

<target name="echo-month"> 
    <script prefix="utils" language="C#"> 
     <code> 
      <![CDATA[ 
       [Function("GetMonth")] 
       public static string GetMonth() { 
        return System.DateTime.Now.ToLongDateString().Split(new Char[]{' '})[1]; 
       } 
      ]]> 
     </code> 
    </script> 

    <property name="the_month" value="${utils::GetMonth()}"/> 
    <echo message="The current month is ${the_month}"/> 
</target> 
0

가 왜 방법 format-to-string를 사용할 수 있습니까? 이 방법은 NANT의 최신 버전에 내장되어 있으므로 자신 만의 역할을 수행 할 이유가 없습니다.

Month: 
${datetime::format-to-string(datetime::now(), 'MMMM')} 

Format in question: 
${datetime::format-to-string(datetime::now(), 'MMMM d, yyyy')} 

더 많은 정보를 원하시면 다음의 링크를 사용하여

http://nant.sourceforge.net/release/0.92/help/functions/datetime.format-to-string%28System.DateTime,System.String%29.html

http://www.csharp-examples.net/string-format-datetime/