timestamp

Discussion in 'XML' started by Thomas Mann, Oct 13, 2004.

  1. Thomas Mann

    Thomas Mann Guest

    Hello,

    using XSLT 2.0 I can get a timestamp with the following line:
    <xsl:value-of select="current-dateTime()"/>
    How can I format the date and the time ? For example I do not want the
    milliseconds to be shown.

    BR
    Thomas
    Thomas Mann, Oct 13, 2004
    #1
    1. Advertising

  2. Thomas Mann wrote:


    > using XSLT 2.0 I can get a timestamp with the following line:
    > <xsl:value-of select="current-dateTime()"/>
    > How can I format the date and the time ? For example I do not want the
    > milliseconds to be shown.


    Well, check the XPath 2.0 function reference, it shows a function
    http://www.w3.org/TR/xslt20/#function-format-dateTime
    format-dateTime that should allow you to format the result returned by
    current-dateTime().
    Here is an example, the second argument to format-dateTime is a string
    with a so called picture which in my view would better be called
    formatting pattern:

    <xsl:template match="/">
    <xsl:variable name="now" select="current-dateTime()" />
    <root>
    <result-unformatted><xsl:value-of select="$now" /></result-unformatted>
    <result-formatted picture="[Y]-[M]-[D]">
    <xsl:value-of select="format-dateTime($now, '[Y]-[M]-[D]')" />
    </result-formatted>
    <result-formatted picture="[Y]-[M]-[D]T[H]:[m]:">
    <xsl:value-of select="format-dateTime($now,
    '[Y]-[M]-[D]T[H]:[m]:')" />
    </result-formatted>
    </root>
    </xsl:template>

    An example output here on my machine with Saxon 8.1.1 is

    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    <result-unformatted>2004-10-14T12:27:39.921+02:00</result-unformatted>
    <result-formatted picture="[Y]-[M]-[D]">2004-10-14</result-formatted>
    <result-formatted
    picture="[Y]-[M]-[D]T[H]:[m]:">2004-10-14T12:27:39</result-formatted>
    </root>


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Oct 14, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Manzoorul Hassan

    Convert to NTP Timestamp

    Manzoorul Hassan, Mar 11, 2005, in forum: Perl
    Replies:
    1
    Views:
    2,710
    Jim Gibson
    Mar 11, 2005
  2. Shawn

    displaying sybase timestamp

    Shawn, Jan 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,148
    Shawn
    Jan 27, 2004
  3. Greg Collins [MVP]

    File Timestamp and Saving Transformed XML to Server

    Greg Collins [MVP], Jul 8, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    463
    Greg Collins [MVP]
    Jul 12, 2004
  4. Roger Twomey

    Using SQL Server Timestamp

    Roger Twomey, Sep 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    23,765
    Greg Burns
    Sep 10, 2004
  5. =?Utf-8?B?bXliYXBweQ==?=
    Replies:
    7
    Views:
    13,069
    =?Utf-8?B?Zng=?=
    Oct 20, 2004
Loading...

Share This Page