
- 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
C# General Date Short Time ("g") Format Specifier
The Generate Date Short Time format specifier is a combination of the short date ("d") and short time ("t") patterns, separated by a space.
Set a date using DateTime.
DateTime dt = new DateTime(2018, 10, 2, 7, 59, 20);
Now, use the (“g”) format specifier.
dt.ToString("g", DateTimeFormatInfo.InvariantInfo));
Example
using System; using System.Globalization; class Demo { static void Main() { DateTime dt = new DateTime(2018, 10, 2, 7, 59, 20); Console.WriteLine(dt.ToString("g", DateTimeFormatInfo.InvariantInfo)); Console.WriteLine(dt.ToString("g", CultureInfo.CreateSpecificCulture("en-us"))); } }
Output
10/02/2018 07:59 10/2/2018 7:59 AM
- Related Articles
- General Date Long Time ("G") Format Specifier in C#
- Full Date Short Time ("f") Format Specifier in C#
- Short Date ("d") Format Specifier
- Short Time ("t") Format Specifier in C#
- Full Date Long Time ("F") Format Specifier in C#
- Long Date ("D") Format Specifier in C#
- Long Time ("T") Format Specifier in C#
- C# Currency ("C") Format Specifier
- C# Exponential (“E”) Format Specifier
- C# Percent ("P") Format Specifier
- C# Numeric (“N”) Format Specifier
- C# Decimal ("D") Format Specifier
- C# Hexadecimal ("X") Format Specifier
- C# Fixed-Point (“F”) Format Specifier
- Sortable ("s") Format Specifier in C#

Advertisements