如何在XSLt文件中以(dd / mm / yyyy)格式显示日期。请帮助我。
我试过并将其显示为2018-04-13Z
<xsl:stylesheet xmlns:ex="http://exslt.org/dates-and-times" extension-element-prefixes="ex">
<xsl:value-of select="ex:date-time()"/>
以上代码以(dd / mm / yyyy)格式打印为(YYYY,MM,DD)。
答案 0 :(得分:1)
希望这个答案充分利用。 2.0
<xsl:value-of select="format-date(., '[M01]/[D01]/[Y0001]')"/>
1.0
<xsl:function name="ex:date-time">
<xsl:param name="date"/>
<xsl:variable name="yy" select="substring-before($date,'-')"/>
<xsl:variable name="mm" select="substring-before(substring-after($date,'-'),'-')"/>
<xsl:variable name="dd" select="substring-before(substring-after(substring-after($date,'-'),'-'),'Z')"/>
<xsl:value-of select="concat($dd,'/',$mm,'/',$yy)"/>
</xsl:function>
感谢, 乌代
答案 1 :(得分:1)
XSLT 1.0没有内置函数来格式化日期。 http://exslt.org/date/index.html提供的扩展也提到format-date()
函数不稳定。
在这种情况下,您可以使用substring()
函数从DD
返回的日期获取MM
,YYYY
和ex:date-time()
部分,然后使用concat()
函数,将它们与/
分隔符连接起来。
<xsl:template match="/">
<xsl:variable name="currDt" select="ex:date-time()" />
<currDate><xsl:value-of select="$currDt" /></currDate>
<formattedDate>
<xsl:value-of select="concat(substring($currDt, 9, 2), '/', substring($currDt, 6, 2), '/', substring($currDt, 1, 4))" />
</formattedDate>
</xsl:template>
输出
<currDate>2018-04-13T14:39:14+05:1800000</currDate>
<formattedDate>13/04/2018</formattedDate>