Skip to content

Allows you to produce a custom .NET date/time format by providing the layout of a reference date formatted example

License

Notifications You must be signed in to change notification settings

jmcd/MagicalTimeFormat

Repository files navigation

Inspired by Go's Time.Format Layout, this package allows you to produce a custom .NET date/time format by providing the layout of a reference date formatted example.

Install nuget package.

var formatFactory = new FormatFactory();

var dateFormat = formatFactory.FormatByParsing("January 02, 2006"); // Produces "MMMM dd, yyyy"

By default, the factory uses the current culture, and the reference date/time

Mon Jan 2 15:04:05 -07:00 2006

You can use specific cultures (IFormatProviders), and another reference date. You can also specify that you only care about formatting date components or time components.

var frenchCulture = CultureInfo.GetCultureInfo("fr");
var formatFactory = new FormatFactory(new DateTime(2006, 1, 2), ReferenceKind.DateOnly, frenchCulture);

var format = formatFactory.FormatByParsing("janvier '06"); // Produces "MMMM 'yy"

About

Allows you to produce a custom .NET date/time format by providing the layout of a reference date formatted example

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published