使用 XSLT 将时间戳转换为日期

发布于 2024-12-09 02:28:25 字数 193 浏览 0 评论 0原文

我有这样的节点:

<item id="37" publish_time="1293829200">

How to conversion @publish_time to date like dd.mm.yyyy?

我正在使用 libxslt

I have node like:

<item id="37" publish_time="1293829200">

How to convert @publish_time to date like dd.mm.yyyy?

I'm using libxslt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尐偏执 2024-12-16 02:28:25

这是我编写的一个模板,用于将秒转换为更易读的格式。您可以扩展它以满足您的需求:

<xsl:template name="convertSecsToTimeStamp">
            <xsl:param name="seconds"/> 
            <xsl:variable name="hours" select="floor($seconds div (60 * 60))"/>
            <xsl:variable name="divisor_for_minutes" select="$seconds mod (60 * 60)"/>
            <xsl:variable name="minutes" select="floor($divisor_for_minutes div 60)"/>
            <xsl:variable name="divisor_for_seconds" select="$divisor_for_minutes mod 60"/>
            <xsl:variable name="secs" select="ceiling($divisor_for_seconds)"/>
            <xsl:choose>
                <xsl:when test="$hours < 10">
                    <xsl:text>0</xsl:text><xsl:value-of select="$hours"/><xsl:text>hh</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$hours"/><xsl:text>hh</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:choose>
                <xsl:when test="$minutes < 10">
                    <xsl:text>0</xsl:text><xsl:value-of select="$minutes"/><xsl:text>mm</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$minutes"/><xsl:text>mm</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:choose>
                <xsl:when test="$secs < 10">
                    <xsl:text>0</xsl:text><xsl:value-of select="$secs"/><xsl:text>ss</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$secs"/><xsl:text>ss</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>

Here is a template that I wrote to convert seconds to a more readable format. You can extend it to cover your needs :

<xsl:template name="convertSecsToTimeStamp">
            <xsl:param name="seconds"/> 
            <xsl:variable name="hours" select="floor($seconds div (60 * 60))"/>
            <xsl:variable name="divisor_for_minutes" select="$seconds mod (60 * 60)"/>
            <xsl:variable name="minutes" select="floor($divisor_for_minutes div 60)"/>
            <xsl:variable name="divisor_for_seconds" select="$divisor_for_minutes mod 60"/>
            <xsl:variable name="secs" select="ceiling($divisor_for_seconds)"/>
            <xsl:choose>
                <xsl:when test="$hours < 10">
                    <xsl:text>0</xsl:text><xsl:value-of select="$hours"/><xsl:text>hh</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$hours"/><xsl:text>hh</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:choose>
                <xsl:when test="$minutes < 10">
                    <xsl:text>0</xsl:text><xsl:value-of select="$minutes"/><xsl:text>mm</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$minutes"/><xsl:text>mm</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:choose>
                <xsl:when test="$secs < 10">
                    <xsl:text>0</xsl:text><xsl:value-of select="$secs"/><xsl:text>ss</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$secs"/><xsl:text>ss</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文