如何在 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())}
仅返回月份数字,而不返回名称。
How do I get the current month name in NAnt?
I'm using a task like the one below to update our site label, which shows the date / time that the site was built. However, I need the date to be in a specific format, rather than varying depending on the machine format.
<xmlpoke file="\\path\to\server\folder\Web.config"
xpath="/configuration/appSettings/add[@key = 'SiteLabel']/@value"
value="[SQLServer].[SQLDatabase] - ${datetime::to-string(datetime::now())}" />
The format I need is "MMM DD, YYYY"
. NAnt doesn't seem to allow me to specify the format, but I can get the individual parts of the date using NAnt functions.
Is there any way I can get the name of the current month, using NAnt functions?
${datetime::get-month(datetime::now())}
only returns the month number, not the name.
发布评论
评论(3)
更优雅的方式:
A more elegant way:
它可能不优雅,但你可以这样:
It may not be elegant, but you could something like this:
为什么不使用
format-to-string
方法?该方法内置于最新版本的 NANT 中,因此没有理由自行扮演。使用以下链接了解更多信息:
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/
Why not use the method
format-to-string
? The method is built into the latest version of NANT, so there is no reason to role-your-own.Use the following links for more info:
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/