PC Review


Reply
Thread Tools Rate Thread

DateTimeFormatInfo, Culture and custom formatting

 
 
George Ionescu
Guest
Posts: n/a
 
      6th Jul 2004
Hello all,

given the following piece of code:

DateTimeFormatInfo dfi = (new CultureInfo("Ro-ro")).DateTimeFormat;
DateTime now = DateTime.Now;
string strDate = now.ToString("dd-MMM-yyyy", dfi);

the strDate contains the string '21-iul.-2004'

What's with the dot after the month's name ? Am I doing something wrong here
?

Thank you.
Regards,
George Ionescu


 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmFrb2IgQ2hyaXN0ZW5zZW4=?=
Guest
Posts: n/a
 
      6th Jul 2004
Hey George,

I guess this is how Microsoft thinks that dates are formatted in Romania :-) If you do not like this format you can change it using DateTimeFormatInfo.AbbreviatedMonthNames:

DateTimeFormatInfo dfi = (new CultureInfo("Ro-ro")).DateTimeFormat;
DateTime now = DateTime.Now;
dfi.AbbreviatedMonthNames = new string[13] { "ian", "feb", "mar", "apr", "mai", "iun", "iul", "aug", "sep", "oct", "nov", "dec", "" };
string strDate = now.ToString("dd-MMM-yyyy", dfi);

Regards, Jakob.


"George Ionescu" wrote:

> Hello all,
>
> given the following piece of code:
>
> DateTimeFormatInfo dfi = (new CultureInfo("Ro-ro")).DateTimeFormat;
> DateTime now = DateTime.Now;
> string strDate = now.ToString("dd-MMM-yyyy", dfi);
>
> the strDate contains the string '21-iul.-2004'
>
> What's with the dot after the month's name ? Am I doing something wrong here
> ?
>
> Thank you.
> Regards,
> George Ionescu
>
>
>

 
Reply With Quote
 
George Ionescu
Guest
Posts: n/a
 
      6th Jul 2004
Hello Jakob,

Thanks, that worked. One other question: I'd like to support different date
separators (e.g. dot, comma, slash); what should I use to parse a string and
construct a date? Should I go for regular expressions or is there another
way (date.ParseExact only allows one format).

Thank you.
Regards,
George Ionescu

"Jakob Christensen" <(E-Mail Removed)> wrote in message
news:A05DE967-72A6-457D-A9D3-(E-Mail Removed)...
> Hey George,
>
> I guess this is how Microsoft thinks that dates are formatted in Romania

:-) If you do not like this format you can change it using
DateTimeFormatInfo.AbbreviatedMonthNames:
>
> DateTimeFormatInfo dfi = (new CultureInfo("Ro-ro")).DateTimeFormat;
> DateTime now = DateTime.Now;
> dfi.AbbreviatedMonthNames = new string[13] { "ian", "feb", "mar", "apr",

"mai", "iun", "iul", "aug", "sep", "oct", "nov", "dec", "" };
> string strDate = now.ToString("dd-MMM-yyyy", dfi);
>
> Regards, Jakob.
>
>
> "George Ionescu" wrote:
>
> > Hello all,
> >
> > given the following piece of code:
> >
> > DateTimeFormatInfo dfi = (new CultureInfo("Ro-ro")).DateTimeFormat;
> > DateTime now = DateTime.Now;
> > string strDate = now.ToString("dd-MMM-yyyy", dfi);
> >
> > the strDate contains the string '21-iul.-2004'
> >
> > What's with the dot after the month's name ? Am I doing something wrong

here
> > ?
> >
> > Thank you.
> > Regards,
> > George Ionescu
> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?SmFrb2IgQ2hyaXN0ZW5zZW4=?=
Guest
Posts: n/a
 
      6th Jul 2004
Hey George,

I don't think there is an easy way to do this. Regular expressions may be the best solution. You can also use the property DateTimeFormatInfo.DateSeparator to specify which date separator you wish to use. But I don't think there is any built-in way for supporting more that one separator unless you want to try parsing the string with a number of different separators using DateTimeFormatInfo.DateSeparator.

Regards, Jakob.


"George Ionescu" wrote:

> Hello Jakob,
>
> Thanks, that worked. One other question: I'd like to support different date
> separators (e.g. dot, comma, slash); what should I use to parse a string and
> construct a date? Should I go for regular expressions or is there another
> way (date.ParseExact only allows one format).
>
> Thank you.
> Regards,
> George Ionescu
>
> "Jakob Christensen" <(E-Mail Removed)> wrote in message
> news:A05DE967-72A6-457D-A9D3-(E-Mail Removed)...
> > Hey George,
> >
> > I guess this is how Microsoft thinks that dates are formatted in Romania

> :-) If you do not like this format you can change it using
> DateTimeFormatInfo.AbbreviatedMonthNames:
> >
> > DateTimeFormatInfo dfi = (new CultureInfo("Ro-ro")).DateTimeFormat;
> > DateTime now = DateTime.Now;
> > dfi.AbbreviatedMonthNames = new string[13] { "ian", "feb", "mar", "apr",

> "mai", "iun", "iul", "aug", "sep", "oct", "nov", "dec", "" };
> > string strDate = now.ToString("dd-MMM-yyyy", dfi);
> >
> > Regards, Jakob.
> >
> >
> > "George Ionescu" wrote:
> >
> > > Hello all,
> > >
> > > given the following piece of code:
> > >
> > > DateTimeFormatInfo dfi = (new CultureInfo("Ro-ro")).DateTimeFormat;
> > > DateTime now = DateTime.Now;
> > > string strDate = now.ToString("dd-MMM-yyyy", dfi);
> > >
> > > the strDate contains the string '21-iul.-2004'
> > >
> > > What's with the dot after the month's name ? Am I doing something wrong

> here
> > > ?
> > >
> > > Thank you.
> > > Regards,
> > > George Ionescu
> > >
> > >
> > >

>
>
>

 
Reply With Quote
 
George Ionescu
Guest
Posts: n/a
 
      6th Jul 2004
Thanks Jakob.

I'll go for RegEx, then.

Regards,
George Ionescu

"Jakob Christensen" <(E-Mail Removed)> wrote in message
news:11ABB8D2-7C09-4564-9FDE-(E-Mail Removed)...
> Hey George,
>
> I don't think there is an easy way to do this. Regular expressions may be

the best solution. You can also use the property
DateTimeFormatInfo.DateSeparator to specify which date separator you wish to
use. But I don't think there is any built-in way for supporting more that
one separator unless you want to try parsing the string with a number of
different separators using DateTimeFormatInfo.DateSeparator.
>
> Regards, Jakob.
>
>
> "George Ionescu" wrote:
>
> > Hello Jakob,
> >
> > Thanks, that worked. One other question: I'd like to support different

date
> > separators (e.g. dot, comma, slash); what should I use to parse a string

and
> > construct a date? Should I go for regular expressions or is there

another
> > way (date.ParseExact only allows one format).
> >
> > Thank you.
> > Regards,
> > George Ionescu
> >
> > "Jakob Christensen" <(E-Mail Removed)> wrote in message
> > news:A05DE967-72A6-457D-A9D3-(E-Mail Removed)...
> > > Hey George,
> > >
> > > I guess this is how Microsoft thinks that dates are formatted in

Romania
> > :-) If you do not like this format you can change it using
> > DateTimeFormatInfo.AbbreviatedMonthNames:
> > >
> > > DateTimeFormatInfo dfi = (new CultureInfo("Ro-ro")).DateTimeFormat;
> > > DateTime now = DateTime.Now;
> > > dfi.AbbreviatedMonthNames = new string[13] { "ian", "feb", "mar",

"apr",
> > "mai", "iun", "iul", "aug", "sep", "oct", "nov", "dec", "" };
> > > string strDate = now.ToString("dd-MMM-yyyy", dfi);
> > >
> > > Regards, Jakob.
> > >
> > >
> > > "George Ionescu" wrote:
> > >
> > > > Hello all,
> > > >
> > > > given the following piece of code:
> > > >
> > > > DateTimeFormatInfo dfi = (new CultureInfo("Ro-ro")).DateTimeFormat;
> > > > DateTime now = DateTime.Now;
> > > > string strDate = now.ToString("dd-MMM-yyyy", dfi);
> > > >
> > > > the strDate contains the string '21-iul.-2004'
> > > >
> > > > What's with the dot after the month's name ? Am I doing something

wrong
> > here
> > > > ?
> > > >
> > > > Thank you.
> > > > Regards,
> > > > George Ionescu
> > > >
> > > >
> > > >

> >
> >
> >



 
Reply With Quote
 
David Elliott
Guest
Posts: n/a
 
      6th Jul 2004
Here are the 4 RE's that I have come up with to parse dates from a string.
These take into account different seperators and languagues that have
2 words for a month.

(\d+(?<mark>[-| |/|\.])[^\d|^ ]+ *[^\d|^ ]*\k<mark>\d+)
(\d+ *(?<mark>[ |/|\.|-]) *\d+ *\k<mark> *\d+)
([a-zA-Z]+[\.]* +\d+ *, *\d+)
([a-zA-Z]+[\.]* +[a-zA-Z]* *\d+ *, *\d+)

As with most things there is more than one way of doing it. This is what
worked for me.

You can take the results and pass it into the Parse() to see if it is a valid date.

try {
CultureInfo cinfo = new CultureInfo(name, false);
date = DateTime.Parse(REresultText, cinfo.DateTimeFormat);
}

Cheers,
Dave


On Tue, 6 Jul 2004 16:32:40 +0300, "George Ionescu" <(E-Mail Removed)> wrote:

>Thanks Jakob.
>
>I'll go for RegEx, then.
>
>Regards,
>George Ionescu
>
>"Jakob Christensen" <(E-Mail Removed)> wrote in message
>news:11ABB8D2-7C09-4564-9FDE-(E-Mail Removed)...
>> Hey George,
>>
>> I don't think there is an easy way to do this. Regular expressions may be

>the best solution. You can also use the property
>DateTimeFormatInfo.DateSeparator to specify which date separator you wish to
>use. But I don't think there is any built-in way for supporting more that
>one separator unless you want to try parsing the string with a number of
>different separators using DateTimeFormatInfo.DateSeparator.
>>
>> Regards, Jakob.
>>
>>
>> "George Ionescu" wrote:
>>
>> > Hello Jakob,
>> >
>> > Thanks, that worked. One other question: I'd like to support different

>date
>> > separators (e.g. dot, comma, slash); what should I use to parse a string

>and
>> > construct a date? Should I go for regular expressions or is there

>another
>> > way (date.ParseExact only allows one format).
>> >
>> > Thank you.
>> > Regards,
>> > George Ionescu
>> >
>> > "Jakob Christensen" <(E-Mail Removed)> wrote in message
>> > news:A05DE967-72A6-457D-A9D3-(E-Mail Removed)...
>> > > Hey George,
>> > >
>> > > I guess this is how Microsoft thinks that dates are formatted in

>Romania
>> > :-) If you do not like this format you can change it using
>> > DateTimeFormatInfo.AbbreviatedMonthNames:
>> > >
>> > > DateTimeFormatInfo dfi = (new CultureInfo("Ro-ro")).DateTimeFormat;
>> > > DateTime now = DateTime.Now;
>> > > dfi.AbbreviatedMonthNames = new string[13] { "ian", "feb", "mar",

>"apr",
>> > "mai", "iun", "iul", "aug", "sep", "oct", "nov", "dec", "" };
>> > > string strDate = now.ToString("dd-MMM-yyyy", dfi);
>> > >
>> > > Regards, Jakob.
>> > >
>> > >
>> > > "George Ionescu" wrote:
>> > >
>> > > > Hello all,
>> > > >
>> > > > given the following piece of code:
>> > > >
>> > > > DateTimeFormatInfo dfi = (new CultureInfo("Ro-ro")).DateTimeFormat;
>> > > > DateTime now = DateTime.Now;
>> > > > string strDate = now.ToString("dd-MMM-yyyy", dfi);
>> > > >
>> > > > the strDate contains the string '21-iul.-2004'
>> > > >
>> > > > What's with the dot after the month's name ? Am I doing something

>wrong
>> > here
>> > > > ?
>> > > >
>> > > > Thank you.
>> > > > Regards,
>> > > > George Ionescu
>> > > >
>> > > >
>> > > >
>> >
>> >
>> >

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
custom culture Tony Johansson Microsoft C# .NET 3 24th Jul 2010 12:32 AM
Create a custom culture that might be wrong Tony Johansson Microsoft C# .NET 1 28th Mar 2010 10:53 AM
When is it a need for a custom Culture Tony Johansson Microsoft C# .NET 2 27th Mar 2010 06:57 PM
Datagrid culture and money formatting issue Earl Microsoft VB .NET 2 30th Jul 2005 12:16 PM
Date.ToString formatting for a culture =?Utf-8?B?QnJpYW4gTm9ybWFu?= Microsoft Dot NET Compact Framework 2 12th Jan 2005 09:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:58 AM.