XSLT Format Date

回眸只為那壹抹淺笑 提交于 2020-01-14 09:21:08

问题


I have a date in this format

10/12/2011 12:55:00 PM (MM-DD-YYYY time)

I would like to format this date into

12/10/2011 (DD-MM-YYYY) time to be removed 

using XSLT? the complexity I find is sometimes the input date can look like

7/12/2011 12:55:00 PM (only one number to the front instead of 07)

Can someone please show me a way to implement this? many thanks in advance.


回答1:


It is easy to obtain desired result using only standard XPath string functions like substring-before, substring-after and substring, e.g.:

<xsl:variable name="input">7/12/2011 12:55:00 PM</xsl:variable>

<xsl:value-of select="concat(
              substring-before(substring-after($input, '/'), '/'), '/',
              substring-before($input, '/'), '/',
              substring(substring-after(substring-after($input, '/'), '/'), 1, 4)
              )"/>


来源:https://stackoverflow.com/questions/9077233/xslt-format-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!