
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Format TimeSpan in C#
You can format a TimeSpan in the hh: mm: ss format in C#.
Firstly, set the TimeSpan −
TimeSpan ts = new TimeSpan(9, 15, 30);
To format TimeSpan −
{0:hh\:mm\:ss}
The following is the code −
Example
using System; using System.Linq; public class Demo { public static void Main() { TimeSpan ts = new TimeSpan(9, 15, 30); Console.WriteLine("{0:hh\:mm\:ss}", ts); } }
Output
09:15:30
- Related Articles
- C# TimeSpan Min value
- C# TimeSpan Max value
- C# Program to Subtract Two TimeSpan
- C# Program to Add Two TimeSpan
- Difference between TimeSpan Seconds() and TotalSeconds()
- Format specifiers in C
- String format for DateTime in C#
- String format for Double in C#
- Sortable ("s") Format Specifier in C#
- Get the drive format in C#
- C# Currency ("C") Format Specifier
- C# Enum Format Method
- Month ("M", "m") Format Specifier in C#
- Short Time ("t") Format Specifier in C#
- Long Time ("T") Format Specifier in C#

Advertisements