dotnetstrftime 1.1.0 copy "dotnetstrftime: ^1.1.0" to clipboard
dotnetstrftime: ^1.1.0 copied to clipboard

Package offering support for formatting DateTime's according to the same rules as .NET does with their Format Strings.

example/dotnetstrftime_example.dart

import 'package:dotnetstrftime/dotnetstrftime.dart';

void main() {
  // May 8th, 2023 T 2:42:33.2332
  var dtWithEmptyMilliseconds = DateTime(2023, 05, 08, 14, 42, 50, 000, 678);

  // Formatting with a raw character
  dtWithEmptyMilliseconds.formatAsDotNET("dd"); // "05"

  // Formatting with pre-defined tokens
  dtWithEmptyMilliseconds.formatAsDotNET(DateTimeFormatTokenTypeDotNet.dd.str); // "05"

  // Formatting with a singleton token
  dtWithEmptyMilliseconds.formatAsDotNET("d"); // "5/8/2023"

  // Formatting with custom interjections. Surrounding the element in quotations is a string literal that won't be parsed for tokens
  dtWithEmptyMilliseconds.formatAsDotNET('dd "xyz"'); // "05 xyz"

  /// Catching invalid formatting:
  try {
    // Notice that the closing quotation-mark is missing. This is invalid.
    dtWithEmptyMilliseconds.formatAsDotNET('"pst');
  } on DateTimeFormatException catch (e) {
    print(e);
  }
}
1
likes
150
points
35
downloads

Publisher

verified publisherwinetech.com

Weekly Downloads

Package offering support for formatting DateTime's according to the same rules as .NET does with their Format Strings.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

characters, collection, intl, timezone

More

Packages that depend on dotnetstrftime