DateTimeToStringWithSuffix 1.0.1

Return a DateTime string with suffix e.g. "st", "nd", "rd", "th".
E.g.
Calling ToStringWithSuffix("dd-MMM-yyyy") could return "16th-Jan-2019".

Install-Package DateTimeToStringWithSuffix -Version 1.0.1
dotnet add package DateTimeToStringWithSuffix --version 1.0.1
<PackageReference Include="DateTimeToStringWithSuffix" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DateTimeToStringWithSuffix --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Supports:

  • .NET Core 1.0 and higher
  • .NET Framework 4.5 and higher

Example usage

https://dotnetfiddle.net/zXQX7y

using System;
using DateTimeToStringWithSuffix;

public class Program
{
  public static void Main()
  {
    Console.WriteLine(DateTime.UtcNow.ToString("d MMM"));  // 1 May
    Console.WriteLine(DateTime.UtcNow.ToStringWithSuffix("d MMM"));  // 1st May
    // Console.WriteLine(DateTime.UtcNow.ToStringWithSuffix("MMM")); // ArgumentException - missing "d" or "dd"
  }
}

Throws an ArgumentException if the format param does not contain a d or dd for the date.

Supports:

  • .NET Core 1.0 and higher
  • .NET Framework 4.5 and higher

Example usage

https://dotnetfiddle.net/zXQX7y

using System;
using DateTimeToStringWithSuffix;

public class Program
{
  public static void Main()
  {
    Console.WriteLine(DateTime.UtcNow.ToString("d MMM"));  // 1 May
    Console.WriteLine(DateTime.UtcNow.ToStringWithSuffix("d MMM"));  // 1st May
    // Console.WriteLine(DateTime.UtcNow.ToStringWithSuffix("MMM")); // ArgumentException - missing "d" or "dd"
  }
}

Throws an ArgumentException if the format param does not contain a d or dd for the date.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.1 1,329 5/1/2019