DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Formatting The Time In XSLT

12.05.2006
| 2231 views |
  • submit to reddit
        This takes the known variables of hour and min, in 24 hour clock format, and turns it in to 12 hour am/pm format.

      <xsl:choose>
        <xsl:when test="hour < 12"><xsl:value-of select="hour" />:<xsl:value-of select="format-number(min,'00')" /> AM</xsl:when>
        <xsl:when test="hour = 12"><xsl:value-of select="hour" />:<xsl:value-of select="format-number(min,'00')" /> PM</xsl:when>
        <xsl:when test="hour > 12"><xsl:value-of select="hour - 12" />:<xsl:value-of select="format-number(min,'00')" /> PM</xsl:when>
      </xsl:choose>