Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
Advertisements
