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

outdated

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';
import 'package:dotnetstrftime/src/format_token_type.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("d"); // "5/8/2023"

  // Formatting with pre-defined tokens
  dtWithEmptyMilliseconds.formatAsDotNET(DateTimeFormatTokenTypeDotNet.d.str); // "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('d "xyz"'); // "5/8/2023 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
0
points
39
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)
View/report issues

License

unknown (license)

Dependencies

characters, collection, intl, timezone

More

Packages that depend on dotnetstrftime