Date Format
import "package:flutter/material.dart";
import 'package:intl/intl.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Hello Flutter",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.indigo,
),
home: const FlutterApp(),
);
}
}
class FlutterApp extends StatefulWidget {
const FlutterApp({super.key});
@override
State<StatefulWidget> createState() {
return FlutterState();
}
}
class FlutterState extends State<FlutterApp> {
@override
Widget build(BuildContext context) {
var time = DateTime.now();
return Scaffold(
appBar: AppBar(
title: const Text(
"Hello Flutter Application",
style: TextStyle(fontWeight: FontWeight.bold),
),
centerTitle: true,
backgroundColor: Colors.grey,
),
body: Container(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Current Time: ${DateFormat("Hms").format(time)}",
style: const TextStyle(
fontSize: 25,
),
),
/*Here directly using DateFormat() and Mentioned format "Hms" to it.we have taken format "Hms" & "jms" from
* "date_format.dart" file*/
/*Here above, DateTime object (Here "time") is passed in format() function*/
Text(
"Current Time: ${DateFormat("jms").format(time)}",
style: const TextStyle(
fontSize: 25,
),
),
Text(
"Current Time: ${DateFormat("yMMMMd").format(time)}",
style: const TextStyle(
fontSize: 25,
),
),
Text(
"Current Time: ${DateFormat("yMMMM").format(time)}",
style: const TextStyle(
fontSize: 25,
),
),
Text(
"Current Time: ${DateFormat("QQQQ").format(time)}",
style: const TextStyle(
fontSize: 25,
),
),
/*"QQQQ" denotes the Quarter number.whole year divides in Four Quarters.Jan to March:1st Quarter,
* April to June:2nd Quarter,July to september:3rd Quarter,October to December:4th Quarter*/
Text(
"Current Time: ${DateFormat("yMMMMEEEEd").format(time)}",
style: const TextStyle(
fontSize: 25,
),
),
Text(
"Current Time: ${DateFormat("EEEE").format(time)}",
style: const TextStyle(
fontSize: 25,
),
),
Text(
"Current Time: ${DateFormat("MMMM").format(time)}",
style: const TextStyle(
fontSize: 25,
),
),
const SizedBox(
height: 50,
),
/*In this way, we can format the Time using "Intel"(Intl flutter package) package in Flutter Application*/
ElevatedButton(
onPressed: () {
setState(() {});
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
fixedSize: const Size(350.0, 50.0),
),
child: const Text(
"current Time",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
color: Colors.white),
),
),
],
),
),
),
);
}
}
Comments
Post a Comment