Last active
April 24, 2022 03:51
-
-
Save JaveedIshaq/b6299aee059e861df29f2a47cbc6dda1 to your computer and use it in GitHub Desktop.
How do I convert a date/time string to a DateTime object in Dart?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith( | |
scaffoldBackgroundColor: darkBlue, | |
), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
final parsedDate = DateTime.parse("1974-03-20 00:00:00.000"); | |
@override | |
Widget build(BuildContext context) { | |
return Column(mainAxisAlignment: MainAxisAlignment.center, children: [ | |
Text( | |
'Parse a String to DateTime object Flutter Dart', | |
style: Theme.of(context).textTheme.headline3, | |
), | |
const SizedBox(height: 50), | |
Text( | |
'$parsedDate\nis converted ${parsedDate.runtimeType} type of object', | |
style: Theme.of(context).textTheme.headline4, | |
), | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment