C# DateTime ToLongTimeString() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DateTime

Definition

In C#, DateTime.ToLongTimeString() returns the time of day with seconds, such as 14:30:45 in the invariant culture. The date part is not included.

The layout comes from the current culture. The method is the same as ToString("T").

This is an instance member of System.DateTime. You call it on a DateTime value, such as dt.ToLongTimeString(...). DateTime is a struct, so every value is copied and never changed in place.

Syntax

Call it on a DateTime. It takes no arguments.

C#
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
DateTime dt = new DateTime(2026, 11, 18, 14, 30, 45);
string s = dt.ToLongTimeString();   // "14:30:45"
CallWhat it does
dt.ToLongTimeString()Hours, minutes, and seconds in the current culture.
dt.ToString("T")The same result with a format letter.
dt.ToString("HH:mm:ss", culture)A custom pattern that is the same in every culture.

Milliseconds are not shown. Use the fff pattern (for example HH:mm:ss.fff) when you need them.

Library declarations
C#
public string ToLongTimeString();

Parameters

ParameterDescription
NoneToLongTimeString() takes no parameters.

Return Value

Return ValueDescription
stringThe time in the long time pattern of the current culture. The date and fractions of a second are not included.

C# Examples

Example 1 — Time with Seconds

Print a long time for an afternoon and an early morning value.

C#
using System;
using System.Globalization;

class Program {
    static void Main() {
        CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
        DateTime a = new DateTime(2026, 11, 18, 14, 30, 45);
        DateTime b = new DateTime(2026, 11, 18, 0, 5, 9);
        Console.WriteLine(a.ToLongTimeString());
        Console.WriteLine(b.ToLongTimeString());
    }
}

How It Works

  1. Fixed culture. The invariant culture uses a 24-hour clock with seconds.
  2. Three parts. The result has hours, minutes, and seconds separated by colons.
  3. Small numbers padded. The second value prints 00:05:09 with leading zeros.
  4. Date ignored. Both values are on November 18, but the date is not in the text.

Example 2 — Milliseconds Are Dropped

Show that 999 milliseconds are cut off and that the date does not matter.

C#
using System;
using System.Globalization;

class Program {
    static void Main() {
        CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
        DateTime a = new DateTime(2026, 11, 18, 14, 30, 45, 999);
        DateTime b = new DateTime(2027, 1, 1, 14, 30, 45);
        Console.WriteLine(a.ToLongTimeString());
        Console.WriteLine(a.ToLongTimeString() == b.ToLongTimeString());
    }
}

How It Works

  1. 999 ms. The first value is almost one full second later than 14:30:45.
  2. Cut, not rounded. The text still shows second 45.
  3. Different dates. The second value is in 2027, but has the same clock time.
  4. Equal text. Only the clock matters, so the comparison prints True.

Example 3 — Match ToString Formats

Compare ToLongTimeString with the T format and with a custom pattern.

C#
using System;
using System.Globalization;

class Program {
    static void Main() {
        CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
        DateTime dt = new DateTime(2026, 11, 18, 14, 30, 45);
        Console.WriteLine(dt.ToLongTimeString() == dt.ToString("T"));
        Console.WriteLine(dt.ToLongTimeString() == dt.ToString("HH:mm:ss", CultureInfo.InvariantCulture));
    }
}

How It Works

  1. Same method, new name. ToString("T") uses the long time pattern too.
  2. First check. The two strings are equal, so the result is True.
  3. Custom pattern. For the invariant culture, the long time pattern is exactly HH:mm:ss.
  4. Second check. This is also True, but only because the culture is invariant.

Frequently Asked Questions

Hours, minutes, and seconds, for example 14:30:45 in the invariant culture.
Yes. Both use the long time pattern of the current culture.
No. Use a custom pattern such as HH:mm:ss.fff.
Some cultures use a 12-hour clock. The current culture decides.
Use ToString("HH:mm:ss", CultureInfo.InvariantCulture) or the "o" format so the text is the same everywhere.

Next: ToOADate()

Convert a DateTime to an OLE Automation date (a double used by Excel and COM) with System.DateTime.

ToOADate() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful