Sortable ("s") Format Specifier in C#


The Sortable standard format specifier represents a custom date and time format string.

The format string is defined by the DateTimeFormatInfo.SortableDateTimePattern property.

The custom format string.

yyyy'-'MM'-'dd'T'HH':'mm':'ss

Example

 Live Demo

using System;
class Demo {
   static void Main() {
      DateTime date = new DateTime(2018, 9, 5, 2, 12, 40);
      Console.WriteLine(date.ToString("s"));
   }
}

Output

2018-09-05T02:12:40

Updated on: 23-Jun-2020

330 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements