How to get DateTime in required format?

  • Thread starter Thread starter Guest
  • Start date Start date
G

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?
 
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
 
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");
 
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?
 
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 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...
 
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" />
 
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.
 
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
 
Back
Top