Convert epoch to Date via XSL from XML attribute and display in HTML

烈酒焚心 提交于 2019-11-28 12:55:58

There is no such thing as an "epoch format". AFAICT, your LastBackupDate is actually the number of milliseconds elapsed since 1970-01-01T00:00:00. In XSLT 1.0, you can use the following template to convert it to ISO date-time representation:

<xsl:template name="millisecs-to-ISO">
    <xsl:param name="millisecs"/>

    <xsl:param name="JDN" select="floor($millisecs div 86400000) + 2440588"/>
    <xsl:param name="mSec" select="$millisecs mod 86400000"/>

    <xsl:param name="f" select="$JDN + 1401 + floor((floor((4 * $JDN + 274277) div 146097) * 3) div 4) - 38"/>
    <xsl:param name="e" select="4*$f + 3"/>
    <xsl:param name="g" select="floor(($e mod 1461) div 4)"/>
    <xsl:param name="h" select="5*$g + 2"/>

    <xsl:param name="d" select="floor(($h mod 153) div 5 ) + 1"/>
    <xsl:param name="m" select="(floor($h div 153) + 2) mod 12 + 1"/>
    <xsl:param name="y" select="floor($e div 1461) - 4716 + floor((14 - $m) div 12)"/>

    <xsl:param name="H" select="floor($mSec div 3600000)"/>
    <xsl:param name="M" select="floor($mSec mod 3600000 div 60000)"/>
    <xsl:param name="S" select="$mSec mod 60000 div 1000"/>

    <xsl:value-of select="concat($y, format-number($m, '-00'), format-number($d, '-00'))" />
    <xsl:value-of select="concat(format-number($H, 'T00'), format-number($M, ':00'), format-number($S, ':00'))" />
</xsl:template> 

Example of call:

<xsl:call-template name="millisecs-to-ISO">
    <xsl:with-param name="millisecs" select="1421247632689" />
</xsl:call-template>

Result:

2015-01-14T15:00:33

Here is the simple solution using Java Extension functions

<xsl:value-of select="string(i:ofEpochMilli($millis))" xmlns:i="java:java.time.Instant"/>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!