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 7636421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:40:33+00:00 2026-05-31T07:40:33+00:00

In C#, how does one use the DateTime format strings to control what parts

  • 0

In C#, how does one use the DateTime format strings to control what parts of a date are displayed and at the same time not override the CultureInfo?

System.Globalization.CultureInfo cultureInfoUS = new System.Globalization.CultureInfo("en-US", false);
System.Globalization.CultureInfo cultureInfoGerman = new System.Globalization.CultureInfo("de-DE", false);

System.Threading.Thread.CurrentThread.CurrentCulture = cultureInfoUS;
DateTime date = DateTime.Parse("03-13-2012 01:30:00 PM");

Console.WriteLine(date.ToString(cultureInfoGerman));
//produces 13.03.2012 13:30:00
Console.WriteLine(date.ToString("MM/dd/yyyy", cultureInfoGerman));
//produces 03.13.2012 but should be 13.03.2012

System.Threading.Thread.CurrentThread.CurrentCulture = cultureInfoGerman;
Console.WriteLine(date.ToShortTimeString());
//produces: 13:30
Console.WriteLine(date.ToString("h:mm tt", cultureInfoGerman));
//produces: 1:30 but should be 13:30
Console.WriteLine(date.ToString("h:mm tt", cultureInfoUS));
//produces: 1:30 PM

You can see the comments in the above code. The output is partially adjusted by the CultureInfo but not entirely.

Also, the ToShortDateString and ToShortTimeString methods do not take an IProvider and therefore must rely on the current thread’s culture info. This is illustrated with the first example above. Is the expectation that you should change the current culture, call ToShortDateString and then revert the thread back to the original culture?

  • 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-05-31T07:40:34+00:00Added an answer on May 31, 2026 at 7:40 am

    I don’t understand the comments in your code – the custom date/time format specifiers you are using behave exactly as I would expect. Why would you expect “MM/dd/yyyy” to put the day first?

    If you want a custom format that is based on the pattern used by a given culture, you can build it by looking at DateTimeFormatInfo.ShortDatePattern, DateTimeFormatInfo.ShortTimePattern etc. For example, if you wanted a custom format with the day of week followed by a culture-specific short time, you could use:

    string format = "dddd " + culture.DateTimeFormat.ShortTimePattern;
    Console.WriteLine(DateTime.Now.ToString(format, culture);
    

    Is the expectation that you should change the current culture, call ToShortDateString and then revert the thread back to the original culture?

    No, you should use a standard date/time format string if you want something other than the current culture:

    date.ToString("d", culture); // short date
    date.ToString("t", culture); // short time
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How does one use multiprocessing to tackle embarrassingly parallel problems ? Embarassingly parallel problems
how does one use code to do this: produce 15 random numbers [EDIT: from
How does one use boost::spirit with an input that consists of something other than
How does one use the CGRectIntegral function? I understand it's purpose. The documentation isn't
In .net, does a bool[] use one bit or one byte per array item?
How does one compare single character strings in Perl? Right now, I'm tryin to
How do I use current date & time as the value for the findValue
I am running in very strange date range query problem. When I use DateTime.now.utc
So apparently Microsoft does not have a Months Enum on their Date structure. What
does one perform better over the other in terms of indexing/quering etc ? e.g.

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.