Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: ms:format-time to show eastern time

323 views
Skip to first unread message

Martin Honnen

unread,
Mar 31, 2009, 8:17:28 AM3/31/09
to
Zest4Quest wrote:

> With Martin's help i was able to display the time in a formatted way.But
> the problem i am having is to show the time in local time or atleast eastern
> time..
> When the time is 8:50 pm (PresentTime) and when i use the following it comes
> out as 00:51
>
> <xsl:value-of select="ms:format-time(PresentTime, 'HH:mm')"/>
>

8:50 comes out as 00:51? That sounds odd. Which XSLT processor do you use?

If the format-time function Microsoft provides does not achieve what you
are looking for then - if you use .NET's
System.Xml.Xsl.XslCompiledTransform - might consider to use the .NET
framework itself to format your date or time values. You can do that
with an extension object or extension function, see
http://msdn.microsoft.com/en-us/library/6datxzsd.aspx for details.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

David Lowndes

unread,
Mar 31, 2009, 9:19:25 AM3/31/09
to
>When the time is 8:50 pm (PresentTime) and when i use the following it comes
>out as 00:51

Are you sure the time wasn't 8:51 and the 8 (or 4) hours is the locale
difference from UTC - or something like that?

Dave

David Lowndes

unread,
Mar 31, 2009, 10:53:06 AM3/31/09
to
>The XL element holds a value like this at 10:13 AM EST
>
><PresentTime>2009-03-31T10:13:50.232138-04:00</PresentTime>
>
>after transforming it comes out as 14:13

Right, so you have a 4 hr difference and it appears as though the
output is appearing as UTC.

In something I did where the time in the XML data was stored as UTC I
found the only way I could get the locale output was to write a custom
C# function:

<msxsl:script implements-prefix="jddf" language="C#">
public DateTime ConvertToLocaleDateTime( DateTime dtUtc )
{
<!--Convert UTC to local-->
DateTime t1 = dtUtc.ToLocalTime();
<!--Now lie by saying the local is Utc!-->
return DateTime.SpecifyKind( t1, DateTimeKind.Utc );
}
</msxsl:script>

... and used it like this:

<xsl:variable name="locale_date"
select="jddf:ConvertToLocaleDateTime(.)" />

... you may need something similar.

Dave

Zest4Quest

unread,
Mar 31, 2009, 11:19:03 AM3/31/09
to
Hi David,
Thanks for the reply.Should i put this at the top of the XSL file?
Assuming that when i did i get the error (the line under <msxsl:script )
which says "prefix jddf" is not defined..
Thanks


"David Lowndes" wrote:

> >The XL element holds a value like this at 10:13 AM EST
> >
> ><PresentTime>2009-03-31T10:13:50.232138-04:00</PresentTime>
> >
> >after transforming it comes out as 14:13
>
> Right, so you have a 4 hr difference and it appears as though the
> output is appearing as UTC.
>
> In something I did where the time in the XML data was stored as UTC I
> found the only way I could get the locale output was to write a custom
> C# function:
>
> <msxsl:script implements-prefix="jddf" language="C#">
> public DateTime ConvertToLocaleDateTime( DateTime dtUtc )
> {
> <!--Convert UTC to local-->
> DateTime t1 = dtUtc.ToLocalTime();
> <!--Now lie by saying the local is Utc!-->
> return DateTime.SpecifyKind( t1, DateTimeKind.Utc );
> }
> </msxsl:script>
>

> .... and used it like this:


>
> <xsl:variable name="locale_date"
> select="jddf:ConvertToLocaleDateTime(.)" />
>

> .... you may need something similar.
>
> Dave
>

David Lowndes

unread,
Mar 31, 2009, 11:58:57 AM3/31/09
to
> Thanks for the reply.Should i put this at the top of the XSL file?

The C# function would be in your xslt file - however I'm not saying
it's precisely what you want. I needed to convert UTC times in the XML
data to locale times. Also, it's possibly easier to create and test
any C# function in Visual Studio to be sure it'll do what you want
before trying it in your XSLT.

Dave

Zest4Quest

unread,
Mar 31, 2009, 2:20:02 PM3/31/09
to
One thing i noticed is that the
<xsl:value-of select="ms:format-time(PresentTime, 'HH:mm')"/>
is giving me differrent outputs even when the data is the same as below

first Time
<PresentTime>2009-03-31T14:08:15.1847401-04:00</PresentTime> 18:08

second time
<PresentTime>2009-03-31T14:08:15.1847401-04:00</PresentTime> 14:08

I dont see anything has changed...

David Lowndes

unread,
Mar 31, 2009, 7:33:58 PM3/31/09
to
>One thing i noticed is that the
><xsl:value-of select="ms:format-time(PresentTime, 'HH:mm')"/>
>is giving me differrent outputs even when the data is the same as below
>
>first Time
><PresentTime>2009-03-31T14:08:15.1847401-04:00</PresentTime> 18:08
>
>second time
><PresentTime>2009-03-31T14:08:15.1847401-04:00</PresentTime> 14:08
>
>I dont see anything has changed...

So what was different between "first Time" and "second Time"?

What happens for the 3rd, 4th, etc times?

Dave

0 new messages