XSLT extension methods ms:format-date & ms:format-time both output date & time under .NET (6+)

David Lowndes 2,640 Reputation points MVP
2023-10-06T20:35:20.4833333+00:00

I'm porting a .NET FW application to .NET (6 and above).
The application performs an XML to HTML conversion using an XSLT transform via System.Xml.Xsl.XslCompiledTransform.

Under .NET FW, this XSL line:

<xsl:value-of select="ms:format-date('2001-02-03T01:02:03', '')"/>

Produces:

03/02/2001

UK date format since that's my locale.

However, under .NET 6 (I've also tried 8), it produces:

03/02/2001 01:02:03

Similarly, the ms:format-time function also outputs both the date & time.

Is this a known documented change in behaviour (I've been unable to find anything)?

Developer technologies .NET Other
{count} votes

Accepted answer
  1. Viorel 122.5K Reputation points
    2023-10-07T10:51:06+00:00

    The source of MSFormatDateTime from .NET Framework can be found here:

    The workarounds for .NET seem to work:

    <xsl:value-of select="ms:format-date('2001-02-03T01:02:03', 'd', 'en-gb')"/>
    <xsl:value-of select="ms:format-date('2001-02-03T01:02:03', 'd', 'en-us')"/>
    
    <xsl:value-of select="ms:format-date('2001-02-03T01:02:03', 'D', 'en-gb')"/>
    <xsl:value-of select="ms:format-date('2001-02-03T01:02:03', 'D', 'en-us')"/>
    
    <xsl:value-of select="ms:format-time('2001-02-03T01:02:03', 't', 'en-gb')"/>
    <xsl:value-of select="ms:format-time('2001-02-03T01:02:03', 't', 'en-us')"/>
    
    <xsl:value-of select="ms:format-time('2001-02-03T01:02:03', 'T', 'en-gb')"/>
    <xsl:value-of select="ms:format-time('2001-02-03T01:02:03', 'T', 'en-us')"/>
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.