Date Format

 import "package:flutter/material.dart";

import 'package:intl/intl.dart';

void main() {
runApp(PracticeApp(),);
}
class PracticeApp extends StatelessWidget {
PracticeApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: "DateFormat in Flutter",
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: DateFormatDemo(),
);
}
}
class DateFormatDemo extends StatefulWidget {
DateFormatDemo({super.key});

@override
State<DateFormatDemo> createState() {
return DateFormatState();
}
}
class DateFormatState extends State<DateFormatDemo> {

@override
Widget build(BuildContext context) {

var time = DateTime.now();

return Scaffold(
appBar: AppBar(
title: Text("DateFormat"),
),
body: Center(
child: SingleChildScrollView(
child: Container(
width: 300.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Current Time : ${DateFormat("Hms").format(time)}", style: TextStyle(fontSize: 20.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current Time : ${DateFormat("jms").format(time)}", style: TextStyle(fontSize: 20.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current Time : ${DateFormat("yMMMMd").format(time)}", style: TextStyle(fontSize: 20.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current Time : ${DateFormat("yMMMM").format(time)}", style: TextStyle(fontSize: 20.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current Quarter : ${DateFormat("QQQQ").format(time)}", style: TextStyle(fontSize: 20.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current Time : ${DateFormat("yMMMMEEEEd").format(time)}", style: TextStyle(fontSize: 20.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current Day : ${DateFormat("EEEE").format(time)}", style: TextStyle(fontSize: 20.0),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current Month : ${DateFormat("MMMM").format(time)}", style: TextStyle(fontSize: 20.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current Month : ${DateFormat("LLLL").format(time)}", style: TextStyle(fontSize: 20.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current Month : ${DateFormat("LLL").format(time)}", style: TextStyle(fontSize: 20.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current Date : ${DateFormat("yMEd").format(time)}", style: TextStyle(fontSize: 20.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current Quarter : ${DateFormat("yQQQQ").format(time)}", style: TextStyle(fontSize: 18.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current Date : ${DateFormat("yM").format(time)}", style: TextStyle(fontSize: 20.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current Hour : ${DateFormat("H").format(time)}", style: TextStyle(fontSize: 20.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current Time : ${DateFormat("Hm").format(time)}", style: TextStyle(fontSize: 20.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current Time : ${DateFormat("j").format(time)}", style: TextStyle(fontSize: 20.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current Time : ${DateFormat("jm").format(time)}", style: TextStyle(fontSize: 20.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current Quarter : ${DateFormat("yQQQ").format(time)}", style: TextStyle(fontSize: 20.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current date : ${DateFormat("yMMMd").format(time)}", style: TextStyle(fontSize: 20.0,),),
Divider(thickness: 1.0, color: Colors.black,),
Text("Current date : ${DateFormat("yMMM").format(time)}", style: TextStyle(fontSize: 20.0,),),
SizedBox(height: 30.0,),
ElevatedButton(
onPressed: () {
setState(() {},);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.brown,
fixedSize: Size(300.0, 50.0,),
),
child: Text("Current Date & Time", style: TextStyle(fontSize: 25.0,),),
),
],
),
),
),
),
);
}
}

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter