Change the default DateTime format to yyyy-MM-dd

Is there a way in C# Micro Framework 4.2 to change the default string format?
We would like to use the yyyy-MM-dd by default.

So if I do DateTime.Now.ToString() it would output something like 2013-08-19 12:04:22 by default, instead of 08/19/2013 12:04:22, which is a very confusing date due to month vs day.

I know I can output a DateTime in any format I want, however I need to call such a method everywhere I output a date, and is prone to error.

Thanks for the help :slight_smile:

I suggest using this definition from the Micro Framework:


Well I know I can change the ToString(“yyyy-MM-dd”) method to output with the format I need. That’s what I do already.

My problem is that for example (a common case): I have a method that returns an 'object’
Now all I do is just thatObject.ToString() I don’t know/or I don’t want to treat it as a special case and just do a ToString().

There is a way to do this in a winform for example, by setting the GlobalCulture at the start of each threads. This way I can say the decimal point is ‘,’ or ‘.’ by default, or how the date is displayed/treated for parsing.

Isn’t there a way to change the way the DateTime.ToString() outputs by default in micro framework? Or that would require a recompilation of the firmware?

@ andre.m -

class idontknow : whatever

I like that class :)))

andre.m I think you’re on to something!
I’m trying to change the fields in DateTimeFormatInfo but it is read only, and I’m trying to create a DateTimeFormatInfo but there is no constructor.

Then I tried to change the current Culture, but there is only EN available.
Here’s a little snippet of code that lists all the cultures:

            CultureInfo[] cultures =
            foreach (CultureInfo culture in cultures) Debug.Print("Culture = "
            + culture.Name);

            Debug.Print("Current UI Culture='" +
            CultureInfo.CurrentUICulture.Name + "'");
            ResourceUtility.SetCurrentUICulture(new CultureInfo("fr-FR"));
            Debug.Print("Current UI Culture='" +
            CultureInfo.CurrentUICulture.Name + "'");

With further searching, there seem to be a way to add another culture as a ‘satellite’ resource file, and deploy it along with the code, so the CultureInfo object can be created… But I can’t find how to do this… here is the thread :

Woot I got it to work with the help of the zip files in that thread:

I’ve added a ‘satellite’ project called mscorlib.en with my new culture resource file called en-CA.resx file, with some custom formating, then added the reference of this project to my main project.

A little helper function I’ve made to set the new culture, since ResourceUtility.SetCurrentUICulture(new CultureInfo(“en-CA”)); would not work (I’m not sure why, but iterating through all available cultures worked):

// Note, you have to add a satellite project that have a resource file with your new culture information
        // By default .Net Microframework has only 'en' culture.
        private static void SetUICulture(string cultureName) {
            CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
            foreach (CultureInfo culture in cultures) {
                if (culture.Name == cultureName) {
                    Debug.Print(cultureName + " culture set");

How to use:


Now when I do a DateTime.Now.ToString(), it outputs this way:
2013-08-20 18:19:45

It’s ok, seems to do what I need for now thanks :slight_smile: