datetime only date flutter code example
Example 1: datetime dart format print
import 'package:intl/intl.dart';
main() {
final DateTime now = DateTime.now();
final DateFormat formatter = DateFormat('yyyy-MM-dd');
final String formatted = formatter.format(now);
print(formatted);
}
Example 2: how to show date only in flutter
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
void main() => runApp(App());
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Current Date Example',
home: DateExample(),
);
}
}
class DateExample extends StatelessWidget {
const DateExample({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(child: Text(DateFormat("yyyy-MM-dd").format(DateTime.now()))),
);
}
}
Example 3: how to show date only in flutter
dependencies:
flutter:
sdk: flutter
intl: ^0.16.1