Datetime 南特的月份名称
如何获取NAnt中的当前月份名称 我正在使用下面这样的任务来更新我们的站点标签,它显示站点创建的日期/时间。然而,我需要的日期是在一个特定的格式,而不是根据不同的机器格式Datetime 南特的月份名称,datetime,nant,Datetime,Nant,如何获取NAnt中的当前月份名称 我正在使用下面这样的任务来更新我们的站点标签,它显示站点创建的日期/时间。然而,我需要的日期是在一个特定的格式,而不是根据不同的机器格式 <xmlpoke file="\\path\to\server\folder\Web.config" xpath="/configuration/appSettings/add[@key = 'SiteLabel']/@value" value="[SQLServer].[SQLDatabase] -
<xmlpoke file="\\path\to\server\folder\Web.config"
xpath="/configuration/appSettings/add[@key = 'SiteLabel']/@value"
value="[SQLServer].[SQLDatabase] - ${datetime::to-string(datetime::now())}" />
我需要的格式是“mmmdd,YYYY”
。NAnt似乎不允许我指定格式,但我可以使用NAnt函数获取日期的各个部分
是否有任何方法可以使用NAnt函数获取当前月份的名称?${datetime::get month(datetime::now())}
只返回月号,而不返回名称。它可能并不优雅,但您可以这样:
<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>
${month}
它可能并不优雅,但您可以这样做:
<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>
${month}
更优雅的方式:
<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>
更优雅的方式:
<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>
为什么不使用格式的方法来字符串
?该方法内置于最新版本的NANT中,因此没有理由扮演自己的角色
Month:
${datetime::format-to-string(datetime::now(), 'MMMM')}
Format in question:
${datetime::format-to-string(datetime::now(), 'MMMM d, yyyy')}
有关详细信息,请使用以下链接:
为什么不使用
格式的方法来字符串?该方法内置于最新版本的NANT中,因此没有理由扮演自己的角色
Month:
${datetime::format-to-string(datetime::now(), 'MMMM')}
Format in question:
${datetime::format-to-string(datetime::now(), 'MMMM d, yyyy')}
有关详细信息,请使用以下链接:
谢谢,就像一个符咒,尽管当
语句稍微漂亮时,选择
->。谢谢,就像一个符咒,尽管当
语句稍微漂亮时,选择
->。