【问题标题】:How to format the date in xslt? [duplicate]如何格式化xslt中的日期? [复制]
【发布时间】:2011-02-21 05:57:40
【问题描述】:

我们如何在 xslt 中格式化日期?

例子:

<xsl:value-of select ="name of function(I/P, 'MMM dd, yyyy')"/>

【问题讨论】:

    标签: xslt


    【解决方案1】:

    这可能会有所帮助:ms:format-date Function

    使用文章中的示例,您可以按如下方式格式化日期:

    未编辑日期:2000-02-16T15:56:00

    编辑日期:2000 年 2 月 16 日

    【讨论】:

    • 我们遇到了关于“EnableScript”的错误。我们在 XSLT 中使用了一些 VB 代码来重新格式化日期。因为我无法在我的 XSLT 上应用 EnableScript 标志,所以它们失败了。使用 ms:format-date 函数,我能够删除该代码,并且仍然可以很好地格式化我的日期。
    【解决方案2】:

    如果您使用的是 XSLT 1.0,您可能会发现 EXSLT - Date and Times 中的日期格式化功能很有用,尤其是 format-date。如果您使用的是 XSLT 2.0,则可以使用Formatting Dates and Times 中描述的内置函数。

    作为后者的示例,如果您想以“2020 年 1 月 1 日”格式输出日期,您可以这样写

    <xsl:value-of select="format-date($d, '[MNn,*-3] [D01], [Y0001]')"/>
    

    【讨论】:

    • 如果你也能提供一个例子就好了,因为网址已经过时并且很难找到正确的信息。比如你将如何显示 OP 提到的MMM dd, yyyy?
    • @m.spyratos 添加了调用格式日期的示例。
    猜你喜欢
    • 2013-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-10
    • 1970-01-01
    • 2013-01-31
    • 2021-03-21
    • 1970-01-01
    相关资源
    最近更新 更多