Compartilhar via


ms:format-time Function

Converts standard XSD time formats to characters suitable for output.

string ms:format-time(string datetime, string format [,locale])

Parameters

  • string datetime
    Contains a time-related value in XSD format. For nonstring arguments, this function behaves as if a string() function were applied. If the argument is not a time, the output is an empty string. If it is a valid XSD time and some fields are empty, this function attempts to fill unspecified fields.
  • string format
    Contains a format string, according to Win32 API GetTimeFormat functions.
  • locale [optional]
    Defines the locale to format the data for (for example, "EN_us").

Remarks

The following lists the format characters for ms:format-time().

Character(s) Description

h

Hours as 0-12

hh

Hours as 00-12

H

Hours as 0-23

HH

Hours as 00-23

m

Minutes as 0-59

mm

Minutes as 00-59

s

Seconds as 0-59

ss

Seconds as 00-59

tt

Insert AM or PM, display hours as 12-hour clock

t

Insert A or P, display hours as 12-hour clock

Example

XML Document: (Sample.xml)

<?xml version='1.0'?>
<XMLSamples xml:space="preserve"
         xmlns:dt="urn:schemas-microsoft-com:datatypes">
  <FileDetails>
   <Author>Robert Brown</Author>
   <Date dt:dt="datetime">2000-02-16T15:56:00</Date>
  </FileDetails>
</XMLSamples>

XSLT Style sheet (Sample.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:ms="urn:schemas-microsoft-com:xslt"
      xmlns:dt="urn:schemas-microsoft-com:datatypes">
  <xsl:template match="/">
  <HTML>
  <HEAD>
  </HEAD>
  <BODY> 
   <xsl:for-each select="XMLSamples/FileDetails/Date">
      <DIV>
          Time Unedited:
          <xsl:value-of select="."/>
      </DIV>
      <DIV>
          Time Edited:
          <xsl:value-of select="ms:format-time(., 'hh:mm:sstt')"/>
      </DIV>
   </xsl:for-each>
  </BODY> 
  </HTML>
</xsl:template>
</xsl:stylesheet>

Output

The output HTML page shows the following entries:

Time Unedited: 2000-02-16T15:56:00
Time Edited: 03:56:00PM

See Also

Reference

XML Schemas (XSD) Reference
XML Data Types Reference