StrftimeParser 1.0.1

dotnet add package StrftimeParser --version 1.0.1                
NuGet\Install-Package StrftimeParser -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StrftimeParser" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StrftimeParser --version 1.0.1                
#r "nuget: StrftimeParser, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install StrftimeParser as a Cake Addin
#addin nuget:?package=StrftimeParser&version=1.0.1

// Install StrftimeParser as a Cake Tool
#tool nuget:?package=StrftimeParser&version=1.0.1                

StrftimeParser

StrftimeParser is a .NET Standard 2.0 library that allows you to work with C-style strftime/strptime string formats within .NET.

The project provides a main class called Strftime that exposes a static method Parse, and a static method ToString.

The Parse method is the equivalent of the strptime in time.h of C language, as it allows to obtain a DateTime object given a format specifier and a formatted date string.

The ToString method is the equivalent of the strftime in time.h of C language, as it allows to obtain a formatted date string, given a format specifier and a DateTime object

Usage

To use StrftimeParser in your .NET project, follow these simple steps:

  1. Add the NuGet package StrftimeParser to your .NET project.

  2. Import the StrftimeParser namespace in your code file.

  3. Now call the Parse or the ToString method

Here an example of Parse:

using StrftimeParser;

string strftimeString = "2001-08-23 14:55:02";
string formatSpecifier = "%Y-%m-%d %H:%M:%S";

DateTime dateTime = Strftime.Parse(strftimeString, formatSpecifier);

// dateTime now contains the formatted date as a .NET DateTime object

Here an example of ToString:

using StrftimeParser;

var dt = new DateTime(1970, 1, 2, 3, 4, 5);
var format = "%c";

var res = Strftime.ToString(dt, format);

// res now contains the formatted date string

How to use a specified CultureInfo when parsing

To execute the parsing with a specific Culture, you can pass a CultureInfo instance to the Parse method:

DateTime dateTime = Strftime.Parse(strftimeString, formatSpecifier, CultureInfo.GetCultureInfo("it-IT"));

// dateTime now contains the formatted date as a .NET DateTime object

How to use a specified CultureInfo when converting to string

To execute the parsing with a specific Culture, you can pass a CultureInfo instance to the ToString method:

var result = Strftime.ToString(dt, formatSpecifier, CultureInfo.GetCultureInfo("it-IT"));

// result now contains the formatted string

Compatibility

At the moment, StrftimeParser supports these format specifiers:

  • %a - Abbreviated weekday name *
  • %A - Full weekday name *
  • %b - Abbreviated month name *
  • %B - Full month name *
  • %d - Day of the month as a zero-padded number
  • %D - Short MM/DD/YY date, equivalent to %m/%d/%y
  • %e - Day of the month as a space-padded number
  • %F - Short YYYY-MM-DD date, equivalent to %Y-%m-%d
  • %c - Date and time representation
  • %I - Hour in 12h format (01-12)
  • %p - AM or PM designation
  • %H - Hour in 24h format (00-23)
  • %j - Day of the year (001-366)
  • %m - Month as a decimal number (01-12)
  • %M - Minute (00-59)
  • %n - New-line character ('\n')
  • %t - Horizontal-tab character ('\t')
  • %S - Second (00-61)
  • %T - ISO 8601 time format (HH:MM:SS), equivalent to %H:%M:%S
  • %u - ISO 8601 weekday as number with Monday as 1 (1-7)
  • %w - Weekday as a decimal number with Sunday as 0 (0-6)
  • %y - Year, last two digits (00-99)
  • %Y - Year

* The specifiers marked with an asterisk (*) are locale-dependent.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 143 9/6/2023
1.0.0 163 9/6/2023
0.1.1 147 8/21/2023
0.1.0 167 7/28/2023