How to get DateTime in required format?

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

SevDer

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

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

DateTime.Today.ToString("dd/MM");
 
G

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

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.

He is using the Now function to obtain the time

 
M

Mark Rae [MVP]

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

Guest

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" />
 
G

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

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top