C# Sortable ("s") Format

In this chapter you will learn:

  1. How to use Sortable ("s") Format Specifier
  2. Example to use Sortable ("s") Format Specifier

Description

The "s" format is defined by the DateTimeFormatInfo.SortableDateTimePattern property.

The custom format string is "yyyy'-'MM'-'dd'T'HH':'mm':'ss".

Example

The following example uses the "s" format specifier to display a DateTime and a DateTimeOffset value on a system in the U.S. Pacific Time zone.


//from  www .  j  a va2 s .c o m
using System;

class MainClass
{

  public static void Main()
  {
        DateTime date1 = new DateTime(2012, 5, 10, 6, 30, 0);
        Console.WriteLine(date1.ToString("s"));

  }

}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. What is a class field
  2. Syntax to create a new field
  3. A class with fields
  4. How to declare more than one fields
Home »
  C# Tutorial »
    C# Language »
      C# Date Time Format
C# Standard Date Time Formatter
C# Full Date Long Time ("F") Format
C# Full Date Short Time ("f") Format
C# General Date Long Time ("G") Format
C# General Date Short Time ("g") Format
C# Long Date ("D") Format
C# Long Time ("T") Format
C# Short Date ("d") Format
C# Short Time ("t") Format
C# Month ("M", "m") Format
C# Year Month ("Y", "y") Format
C# RFC1123 ("R", "r") Format
C# Universal Full ("U") Format
C# Universal Sortable ("u") Format
C# Round-trip ("O", "o") Format
C# Sortable ("s") Format