在XSLT中将字符串转换为日期格式 [英] Convert a string to Date format in XSLT
问题描述
我在XML文件中具有以下格式的日期(字符串)值:
I have a date(string) value in an XML file in this format:
Tue Apr 17 03:12:47 IST 2012
我想使用XSL转换将字符串/日期转换为以下格式:
I want to use XSL transformation to convert the string/date into this format:
4/17/2012 03:12:47 AM
如何在XSL转换中做到这一点?
How can I do that in my XSL transform?
推荐答案
使用
-
XSLT 1.0版本,使用 EXSLT-date:format-date 日期扩展
XSLT 1.0 version, use EXSLT - date:format-date date extension
XSLT 2.0版本,请使用 内置:格式化日期和时间 延长日期
XSLT 2.0 version, use built-in: Formatting Dates and Times date extension
但是我的建议是
在XML上,在您隐藏的代码(即渲染时间)上具有标准的XSD日期时间格式
更新:
始终使用XML来处理XSLT,日期应采用标准XSD格式。当前,您输入的内容不是标准格式,因此会引发错误。
Update:
Always XML to process through XSLT, dates should be in standard XSD format. Currently your input is not in standard format so that it throws error.
示例:
Example:
<xsl:variable name="dt" as="xs:dateTime" select="xs:dateTime('2012-10-21T22:10:15')"/>
<xsl:value-of select="format-dateTime($dt, '[Y0001]/[M01]/[D01]')"/>
输出:
OUTPUT:
2012/10/21
2012/10/21
这篇关于在XSLT中将字符串转换为日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!