Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Aug 13, 2009 @ 13:39
    Warren Buckley
    0

    Trying to format UTS date format with umbraco.library:FormatDateTime()

    Hello I was wondering if someone could help me trying to format a UTS date with the XSLT extension umbraco.library:FormatDateTime.

    UTS (Unix Time Stamp) Date = 1250163047
    Actual Date = 13 Aug 2009, 11:30

    Some info on Unix Time Stamp
    http://www.onlineconversion.com/unix_time.htm
    http://en.wikipedia.org/wiki/Unix_time

    I have no idea on how I could handle this problem any suggestions please.

    Thanks,
    Warren :)

     

  • Tim 225 posts 690 karma points
    Aug 13, 2009 @ 13:45
    Tim
    1

    A UNIX timestamp is number of seconds since 1/1/1970 so if you  used the dateAdd method in umbraco:library to add 1250163047 seconds to 1/1/1970 you would get the correct date object returned and you could format as usual.

    T

  • Arnold Visser 418 posts 778 karma points hq c-trib
    Aug 13, 2009 @ 13:51
    Arnold Visser
    1

    I think you'll need some .net code to make the conversion BEFORE using it in xslt.

    http://codeclimber.net.nz/archive/2007/07/10/convert-a-unix-timestamp-to-a-.net-datetime.aspx

    static DateTime ConvertFromUnixTimestamp(double timestamp)
    {
        DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
        return origin.AddSeconds(timestamp);
    }
    
    
    static double ConvertToUnixTimestamp(DateTime date)
    {
        DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
        TimeSpan diff = date - origin;
        return Math.Floor(diff.TotalSeconds);
    }

  • Tommy Poulsen 514 posts 708 karma points
    Aug 13, 2009 @ 13:52
    Tommy Poulsen
    1

    and here is another one http://www.codeproject.com/KB/cs/timestamp.aspx

    >Tommy

     

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Aug 13, 2009 @ 13:57
    Warren Buckley
    0

    OK excellent thanks guys, I will write this as an XSLT extension.

    Warren :)

  • Tim 225 posts 690 karma points
    Aug 13, 2009 @ 13:57
    Tim
    100

    I think this will work in XSLT, not tested:

    <xsl:value-of="umbraco.library:FormatDateTime(umbraco.library:DateAdd('1/1/1970','s', 1250163047), 'MMMM d, yyyy')" />
    
    

    T

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Aug 13, 2009 @ 14:03
    Warren Buckley
    0

    Tim, I tried it but it didn't work.
    Does the 1970 date need to be in a different format?

    <xsl:value-of select="umbraco.library:FormatDateTime(umbraco.library:DateAdd('1/1/1970','s', date[@uts]),'dd.mm.yy @ H:mm')"/>
  • Tim 225 posts 690 karma points
    Aug 13, 2009 @ 14:11
    Tim
    0

    Might need to be like this:

    1970-01-01T00:00:00

    T

  • Tim 225 posts 690 karma points
    Aug 13, 2009 @ 14:13
    Tim
    0

    Example:

    <xsl:value-of="umbraco.library:FormatDateTime(umbraco.library:DateAdd('1970-01-01T00:00:000','s', 1250163047), 'MMMM d, yyyy')" />

    Again not tested - just coding off the top of my head!

    T

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Aug 13, 2009 @ 15:02
    Warren Buckley
    0

    OK Tim did solve it on earlier with the original date format of 01/01/1970 and it was me being dumb with my XPath Selector.
    I should have done date/@uts and NOT date[@uts]

    <xsl:value-of select="umbraco.library:FormatDateTime(umbraco.library:DateAdd('01/01/1970','s', date/@uts),'dd dddd MMM yy @ H:mm')"/>
Please Sign in or register to post replies

Write your reply to:

Draft