Copied to clipboard

Flag this post as spam?

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


  • Kim Andersen 1447 posts 2196 karma points MVP
    Sep 20, 2009 @ 11:53
    Kim Andersen
    0

    Problem with the FormatDateTime

    Hi there

     

    I'm making a RSS-feed for one of my sites in version 4.0.2.1, and would like the <pubDate> to look like this: '

    wed, 23 sep 2009 12:00:00 +0000

     

    So I'll use the FormatDateTime extension in Umbraco like this:

    <pubDate>
    <xsl:value-of select="umbraco.library:FormatDateTime($node/data[@alias='date'], 'ddd, dd MMM yyyy hh:mm:ss')"/> +0000
    </pubDate>

    In my head that would give me the correct format of the date, but it doesn't.

     

    Almost all of if works, except the dayname (ddd). I get this:

    on, 23 sep 2009 12:00:00 +0000

    To the non-danish people: the "on" is short for "onsdag" wich means wednesday :)

     

    If I use four d's instead of three d's I get this result:

    onsdag, 23 sep 2009 12:00:00 +0000

    Wich is the whole name of the day.

     

    Is this a bug in the FormatDateTime, or am I doing it wrong?

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Sep 20, 2009 @ 13:07
    Thomas Höhler
    0

    No, that is because your application is running on a danish windows.

    Try to change the culture in the web.config, eg. for german output I use

     <globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="de-DE" />

    in the system.web section

    hth, Thomas

  • Kim Andersen 1447 posts 2196 karma points MVP
    Sep 20, 2009 @ 14:43
    Kim Andersen
    0

    Ahh okay. Actually the culture-attribute wasn't even there, so I gues it just took the system default language?

     

    But now I have set the culture="en-US" and the dayname is now shown the right way, with three letters. Weird that the danish language only would show the dayname with two letters.

     

    But thank you very much for the help Thomas :)

     

    By the way. Does this have any effect on other parts of my site now that the culture is set to english instead of danish, when its a danish site? I think of either our special danish characters (æ, ø and å) or things like that.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Oct 01, 2009 @ 11:21
    Kim Andersen
    0

    I have a follow-up question to this post.

     

    Now my globalization culture is set to en-US, and my daynames are in the right format in my RSS-feed. But when I use the umbraco.library:formatDate to write out the date, it is off course written in english. This means that this month is spelled October. I would like it to be spelled in Danish like this: oktober.

     

    Is this in some way possible? To use the english daynames in my RSS, but every other places on my site use the danish language?

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Oct 01, 2009 @ 13:52
    Thomas Höhler
    0

    If you are using .NET code you can set the culture for the current Output. But this isn't possible via umbraco.library:FormatDateTime. This function uses the actual culture set via web.config or via culture of the server.

    You can write your own xslt extension:

    Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
    return DateTime.Now.ToString("ddd, dd MMM yyyy hh:mm:ss");

    or

    CultureInfo ci = CultureInfo.CreateSpezificCulture("de-DE");
    return DateTime.Now.ToString("ddd, dd MMM yyyy hh:mm:ss", ci);

    hth,
    Thomas

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Oct 01, 2009 @ 21:51
    Kim Andersen
    0

    I can't write .NET code yet unfortunately. But i tried making a hostname on my Frontpage, with danish as the language. And it did the trick. So now my dates are english in my RSS-feeds, but on the website frontend they are translated to danish.

     

    But thanks for your help anyway Thomas :)

Please Sign in or register to post replies

Write your reply to:

Draft