Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Date Formatting 1

Status
Not open for further replies.

CassidyHunt

IS-IT--Management
Joined
Jan 7, 2004
Messages
688
Location
US
I have an xml file that gives me the date in this format:

2006-01-19T02:50:00.0000000-08:00

I would like to have it in this format:
01/19/2006 8:00 a.m.

I am loading it using a XSLT file and ASP.Net so I would also need to fire the event off using onload. I found that doesn't work with a table cell.

Here is as close as I have gotten:

Code:
		function getDate(_this) {
			var D = _this.test.replace(/^(\d{4})-(\d{2})-(\d{2})T([0-9:]*)([.0-9]*)(.)(.*)$/,'$1/$2/$3 $4 GMT') //; 
			_this.innerHTML = D;
		}

Any help is appreciated.

Thanks

Cassidy

 
Why not filter it using XSLT? (I'm assuming the XSLT is server-side).

Also, you gave the following times:
[blue]2006-01-19T[red]02:50:00[/red].0000000[red]-08:00[/red][/blue]
and
[blue]01/19/2006 [red]8:00 a.m.[/red][/blue]

the [red]-8:00[/red] refers to the timezone: GMT-8. the [red]02:50:00[/red] is the actual time (followed by loads of decimal places, which I assume can safely be ignored!)

You should consider what timezone you wish the output to appear in: are you happy with GMT-8?

---
Marcus
better questions get better answers - faq581-3339
accessible web design - zioncore.com
 
I would but I have not been able to find anything to format dates using XSLT 1.1. I think that is hte version. 2.0 has some features but the 1. versions don't have any date conversion from what I see and I am not quite familiar with the parsing so I was looking into javascript.

CAn you point me in the right direction to find what I need?
 
Got a template to do what I need. Thank you for your help.

Here is the template.

Code:
<xsl:template name="formatDate">
<!-- variable name: given, alias x -->
<xsl:param name="given"/>
<xsl:variable name="y" select="substring-before($given,'T')" />
<xsl:variable name="CCYY" select="substring-before($y,'-')" />
<xsl:variable name="tmp" select="substring-after($y,'-')" />
<xsl:variable name="MM" select="substring-before($tmp,'-')" />
<xsl:variable name="DD" select="substring-after($tmp,'-')" />
<xsl:variable name="z" select="substring-after($given,'T')" />
<xsl:variable name="hh" select="substring-before($z,':')" />
<xsl:variable name="tmp2" select="substring-after($z,':')" />
<xsl:variable name="mm" select="substring-before($tmp2,':')" />
<xsl:variable name="tmp3" select="substring-after($tmp2,':')" />
<xsl:variable name="hh_norm">
    <xsl:choose>
        <xsl:when test="$hh &gt; 12">
            <xsl:value-of select="$hh - 12" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$hh" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:variable>
<xsl:variable name="sffx">
    <xsl:choose>
        <xsl:when test="$hh &gt; 12">
            <xsl:value-of select="'pm'" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="'am'" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:variable>
<xsl:variable name="mm_norm" select="$mm" />
<xsl:variable name="result" select="concat($MM,'/',$DD,'/',$CCYY,' ',$hh_norm,':',$mm_norm,' ',$sffx)" />
<!-- display result here -->
<xsl:value-of select="$result" />
</xsl:template>

To call
Code:
<xsl:call-template name="formatDate">
     <xsl:with-param name="given" select="FINISH_DATE" />
</xsl:call-template>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top