Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to get DateTime in required format?

Reply
Thread Tools

How to get DateTime in required format?

 
 
Guest
Posts: n/a
 
      08-07-2007
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?


 
Reply With Quote
 
 
 
 
SevDer
Guest
Posts: n/a
 
      08-07-2007
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:(E-Mail Removed)...
> 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?
>
>


 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      08-07-2007
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");

 
Reply With Quote
 
Guest
Posts: n/a
 
      08-07-2007
> 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



 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      08-07-2007
On Aug 7, 11:23 am, "SevDer" <(E-Mail Removed)> 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


 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      08-07-2007
<Smuggy> wrote in message news:(E-Mail Removed)...

>> 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

 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      08-07-2007
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" />

 
Reply With Quote
 
Guest
Posts: n/a
 
      08-07-2007
> 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.CurrentCultu re = New
System.Globalization.CultureInfo("en-GB", False)

After this the Now function works correctly.


>



 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      08-07-2007
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.CurrentCultu re = 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
[2.4.4] creating a datetime.datetime from an XML xs:dateTime Martin Python 0 12-27-2008 08:08 PM
mx.DateTime to datetime.datetime mp Python 1 07-28-2006 10:57 PM
datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Christos TZOTZIOY Georgiou Python 3 09-13-2003 10:44 AM
RE: datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Tim Peters Python 0 09-09-2003 12:57 AM



Advertisments