Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9267313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:31:18+00:00 2026-06-18T14:31:18+00:00

I’m having a slight issue with Thread culture and getting a date to display

  • 0

I’m having a slight issue with Thread culture and getting a date to display properly.
I am overloading the ToString() method of the DateTime class.

With culture “en-CA”, my date is coming out in the right format “yyyy/MM/dd”
but with culture “fr-CA”, my date is coming out “yyyy-MM-dd”

I’ve made some unit test to display the issue.
The english test works but the french always fails.

Even if I change the GetDateInStringMethod to do .ToShortDateString. I still get the same issue.

[Test()]
public void ValidInEnglish()
{
    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-CA");
    Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = Utility.DatePattern;
    DateTime? currentDate = new DateTime(2009,02,7);
    string expected = "2009/02/07";
    string actual = DateUtils.GetDateInString(currentDate);

//This works
    Assert.AreEqual(expected, actual);
}

[Test()]
public void ValidInFrench()
{
    Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA");
    Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = Utility.DatePattern;
    DateTime? currentDate = new DateTime(2009, 02, 7);
    string expected = "2009/02/07";
    string actual = DateUtils.GetDateInString(currentDate);
// This doesn't work
    Assert.AreEqual(expected, actual);
}

public static string GetDateInString(DateTime? obj)
{
    if (obj == null || !obj.HasValue)
    {
        return string.Empty;
    }

    return obj.Value.ToString(Utility.DatePattern);
}

public const string DatePattern = "yyyy/MM/dd";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:31:20+00:00Added an answer on June 18, 2026 at 2:31 pm

    That doesn’t work because using french culture defaults the datetime formatter to use - instead of / as a separator character.

    If you want to keep your date the same no matter the culture then use CultureInfo.InvariantCulture

    if you want to use the french formatting the change your expected test result to "2009-02-07".

    If you are looking for more info check this msdn link.

    And if you want a personal recommendation for a lib to use for dealing with the awesomeness that is Globalization then I’d recommend Noda Time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to understand how to use SyndicationItem to display feed which is
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.