问题描述
我正在使用以下代码在 xslt 程序中显示当前日期.使用日期格式 yyyy-mm-dd 工作正常.但我需要 dd-mmm-yyyy 格式.请帮我做这件事.
I am using the below code to show the current date in xslt program.It's working fine With the date format yyyy-mm-dd. But i need the format dd-mmm-yyyy. Please help me to do this.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:cs="urn:cs"
>
<xsl:value-of select="cs:datenow()"></xsl:value-of>
推荐答案
您已将您的问题标记为 XSLT 2.0,因此我希望您只需使用 current-date
函数获取当前日期http://www.w3.org/TR/xpath-functions/#func-current-date 并使用 XSLT 2.0 函数 format-date
http://www.w3.org/TR/xslt20/#format-date.所以基本上 format-date(current-date(), '[D01]-[MN,*-3]-[Y0001]')
给出了类似 11-JUL-2013.根据您的需要(我不确定
mmm
的格式代表什么,因为大多数日期格式化例程定义了自己的模式)您需要调整 format-date 的图片字符串"参数
,请参阅我链接到的文档.
You have tagged your question as XSLT 2.0 so I would expect you to simply get the current date with the
current-date
function http://www.w3.org/TR/xpath-functions/#func-current-date and to format it with the XSLT 2.0 function format-date
http://www.w3.org/TR/xslt20/#format-date.So basically format-date(current-date(), '[D01]-[MN,*-3]-[Y0001]')
gives a format like 11-JUL-2013
. Depending on your needs (I am not sure what the format mmm
stands for, as most date formatting routines define their own patterns) you need to adapt the "picture string" argument of format-date
, see the documentation I linked to.
这篇关于xslt 日期格式更改 (dd-mmm-yyyy)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!