Temporary date format

  • Thread starter Thread starter N! Xau
  • Start date Start date
N

N! Xau

Hi all,

I have a date in date format:

dDate = cDate("02/16/2005")

I want to use ONE method, or function, to output dDate in format MMM
yyyy
where MMM reflect the national settings of a passed parameter.

For instance,

myConverter(dDate, English) = FEB 2005
myConverter(dDate, French) = FEV 2005


Is that possible?


THX
 
N! Xau said:
Hi all,

I have a date in date format:

dDate = cDate("02/16/2005")

I want to use ONE method, or function, to output dDate in format MMM
yyyy
where MMM reflect the national settings of a passed parameter.

For instance,

myConverter(dDate, English) = FEB 2005
myConverter(dDate, French) = FEV 2005


Is that possible?

Sure, and it's really easy too. First thing to point out is that what
you are dealing with is not "national settings" but "culture", which is
the .NET term that encompasses all the regional and language stuff that
used to be called 'locale'.

Next thing is to decide how you want to reference cultures - you can
either pass around their names, which are things like "en-US" for
English/USA or "fr-FR" for French/France, or you can pass the culture
objects themselves. The objects are CultureInfo objects (in the
System.Globalization namespace) and you can get a pre-defined
CultureInfo as easily as

Dim cifrFR As New CultureInfo("fr-FR")

Finally once you have the CultureInfo you want, just pass it to the
appropriate overload of Date.ToString:

Dim sLocalisedDate As String = dDate.ToString("MMM yyyy", cifrFR)

Note that you might not always get what you expect! for example the MMM
format for February in fr-FR is "févr." - no capital (because French
doesn't capitalise month names) and including the abbreviating period.

Still, that's what the CultureInfo says, so that's what we get!
 
Larry Lard ha scritto:

Note that you might not always get what you expect! for example the MMM
format for February in fr-FR is "févr." - no capital (because French
doesn't capitalise month names) and including the abbreviating period.

Still, that's what the CultureInfo says, so that's what we get!



Thank you very much


N! Xau

MSTC
http://ilovemiliofede.altervista.org
 

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

Back
Top