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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:54:09+00:00 2026-05-31T15:54:09+00:00

I have a DateTime object and I want to output the hour, minute, second,

  • 0

I have a DateTime object and I want to output the hour, minute, second, and fractional second as a string that is localized for the current culture.

There are two issues with this.

First issue is there is no standard DateTime format that will show the fractional seconds. I essentially want to know how to get the long time DateTime format but with fractional seconds.

I could of course get DateTimeFormatInfo.LongTimePattern and append “.fff” to it and pass it to the DateTime.ToString(), but some of the culture specific formats, US specifically, end with AM/PM. So it isn’t that simple.

The second issue is that DateTime.ToString() does not appear to localize the number decimal separator. If I decided to just force each culture to use a hard coded custom time format it still will not create a localized string as the number decimal separator will not be culture specific.

To complicate matters further, some cultures have date time formats that use periods as part of their formatting. This makes it difficult to put a placeholder, for example the period and replace it with a culture specific decimal separator.

For now I have resorted to this workaround:

string format = string.Format("HH:mm:ss{0}fff",
    CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
string time = DateTime.Now.ToString(format);

Which I think should work for every culture that doesn’t have the same decimal separator as the time separator, but that is an assumption.

Of Note: While it would be nice to have a solution to both issues, for my specific application I am more interested in localizing a custom date time format with fractional seconds than using a standard date time format.

  • 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-31T15:54:10+00:00Added an answer on May 31, 2026 at 3:54 pm

    First issue is there is no standard DateTime format that will show the fractional seconds. I essentially want to know how to get the long time DateTime format but with fractional seconds.

    You might consider taking the long format and just replacing “:ss” with “:ss.fff”, possibly using the culture-specific decimal separator:

    string longPattern = culture.DateTimeFormat.LongTimePattern;
    if (!longPattern.Contains(":ss"))
    {
        // ???? Throw an exception? Test this with all system cultures, but be aware
        // that you might see custom ones...
    }
    // Only do it if the long pattern doesn't already contain .fff... although if
    // it does, you might want to replace it using the culture's decimal separator...
    if (!longPattern.Contains(".fff"))
    {
        longPattern = longPattern.Replace(":ss", 
            ":ss" + culture.NumberFormat.DecimalSeparator + "fff");
    }
    string timeText = time.ToString(longPattern, culture);
    

    To complicate matters further, some cultures have date time formats that use periods as part of their formatting. This makes it difficult to put a placeholder, for example the period and replace it with a culture specific decimal separator. Other than that though, it should end up putting the value in the right place. Do you definitely always want three digits though, even if the value is an exact second (or half a second, etc)? Use .FFF if not.

    I suspect that’s why the culture-specific decimal separator isn’t used. I’ve found it odd myself – indeed, I’ve made Noda Time behave the same way, even though I’m not convinced it’s right.

    Ultimately, a lot of issues like this are fundamentally problematic: if a culture has no fixed way of representing “a time with fractional seconds” and you’ve got to represent fractional seconds, then the best you’re going to be able to do is a bit of a kludge.

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

Sidebar

Related Questions

I have an datetime object that I want to remove one hour to display
I have a datetime object, for which I want to create a date string
I have a string like this: 250920111414 I want to create a DateTime object
I have an mktime that I want to have return a datetime object. The
I have a DateTime object I want to compare against an sql datetime field
I have the following method: public object[] GetEventsByUser(DateTime start, DateTime end, string fullUrl) The
I have this object: class a { public string Application; public DateTime From, To;
I have a datetime object, dt , that holds today's date. DateTime dt =
I have a dateTime object in C# and i want to do an insert
I have a object that I serialize with the JavaScriptSerializer and output it in

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.