How to get DateTime in required format?

Discussion in 'ASP .Net' started by Guest, Aug 7, 2007.

  1. Guest

    Guest Guest

    Hello group
    I am using the now function to obtain the time, however because
    my server is located in a different locale, I am getting the wrong
    format - instead of 07/08 etc I am getting 08/07 etc (the American
    format). Is there a simple way to change this?
    Guest, Aug 7, 2007
    #1
    1. Advertising

  2. Guest

    SevDer Guest

    Hi,

    Use DateTime.ParseExact("parsing string", iformatprovider) where in format
    provider you can specify the culture.
    I hope that will be a good start point.

    SevDer
    www.sevder.com

    <Smuggy> wrote in message news:...
    > Hello group
    > I am using the now function to obtain the time, however because
    > my server is located in a different locale, I am getting the wrong
    > format - instead of 07/08 etc I am getting 08/07 etc (the American
    > format). Is there a simple way to change this?
    >
    >
    SevDer, Aug 7, 2007
    #2
    1. Advertising

  3. On Aug 7, 11:14 am, <Smuggy> wrote:
    > Hello group
    > I am using the now function to obtain the time, however because
    > my server is located in a different locale, I am getting the wrong
    > format - instead of 07/08 etc I am getting 08/07 etc (the American
    > format). Is there a simple way to change this?


    to format output you can use the ToString() method with appropriate
    formats as follows

    DateTime.Today.ToString("dd/MM");
    Alexey Smirnov, Aug 7, 2007
    #3
  4. Guest

    Guest Guest

    > Use DateTime.ParseExact("parsing string", iformatprovider) where in format
    > provider you can specify the culture.
    > I hope that will be a good start point.


    I have

    dim a as datetime
    a.parseexact(a.today,"en-GB")

    is this correct?

    >
    > SevDer
    > www.sevder.com
    Guest, Aug 7, 2007
    #4
  5. On Aug 7, 11:23 am, "SevDer" <> wrote:
    > Hi,
    >
    > Use DateTime.ParseExact("parsing string", iformatprovider) where in format
    > provider you can specify the culture.
    > I hope that will be a good start point.
    >


    He is using the Now function to obtain the time


    > > I am using the now function to obtain the time
    Alexey Smirnov, Aug 7, 2007
    #5
  6. <Smuggy> wrote in message news:...

    >> Use DateTime.ParseExact("parsing string", iformatprovider) where in
    >> format
    >> provider you can specify the culture.
    >> I hope that will be a good start point.

    >
    > I have
    >
    > dim a as datetime
    > a.parseexact(a.today,"en-GB")
    >
    > is this correct?


    DateTime.Now.ToString("dd MMM yyyy"), assuming you want both Y2k
    compatability and non-ambiguity...


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Aug 7, 2007
    #6
  7. On Aug 7, 11:37 am, <Smuggy> wrote:
    > > Use DateTime.ParseExact("parsing string", iformatprovider) where in format
    > > provider you can specify the culture.
    > > I hope that will be a good start point.

    >
    > I have
    >
    > dim a as datetime
    > a.parseexact(a.today,"en-GB")
    >
    > is this correct?
    >


    DateTime.ParseExact method converts the string to a date. You have
    already a date value. All what you need is to show that date in the
    format you need. Either use .ToString() method, or change a culture in
    your application.

    Go to web.config and add this

    <globalization culture="en-GB" uiCulture="en-GB" />
    Alexey Smirnov, Aug 7, 2007
    #7
  8. Guest

    Guest Guest

    > Go to web.config and add this
    >
    > <globalization culture="en-GB" uiCulture="en-GB" />


    Thanks, I did it this way, I found it in the msdn

    System.Threading.Thread.CurrentThread.CurrentCulture = New
    System.Globalization.CultureInfo("en-GB", False)

    After this the Now function works correctly.


    >
    Guest, Aug 7, 2007
    #8
  9. On Aug 7, 12:06 pm, <Smuggy> wrote:
    > > Go to web.config and add this

    >
    > > <globalization culture="en-GB" uiCulture="en-GB" />

    >
    > Thanks, I did it this way, I found it in the msdn
    >
    > System.Threading.Thread.CurrentThread.CurrentCulture = New
    > System.Globalization.CultureInfo("en-GB", False)
    >
    > After this the Now function works correctly.


    It will work, but you always have to set the culture for the current
    thread. If your application is designed for UK only, you can specify
    that value on the global level in the web.config file. You also can
    use the @Page Directive

    <%@Page Culture="en-GB" ....

    Hope this helps
    Alexey Smirnov, Aug 7, 2007
    #9
    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. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    685
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    517
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    372
    John Machin
    Jul 28, 2006
  4. Martin
    Replies:
    0
    Views:
    324
    Martin
    Dec 27, 2008
  5. Replies:
    2
    Views:
    738
    M.-A. Lemburg
    Jan 6, 2009
Loading...

Share This Page