Flutter Get Current Date With Day Month Year Format Example Android iOS Tutorial

In Flutter a inbuilt class is available for developers to get current time and date. The class name is DateTime. In today’s tutorial we are using the DateTime class to extract only current Time from mobile. The DateTime class works perfectly in both Android and iOS platform. So in this tutorial we would Flutter Get Current Date With Day Month Year Format Example Android iOS Tutorial. We would convert the date in DD:MM:YY format in current tutorial.

Contents in this project Flutter Get Current Date With Day Month Year Format Example Android iOS Tutorial:

1. Open your project’s main.dart file and import material.dart package.

2. Create void main runApp() method and here we would call or main MyApp class. This is our main Root class.

3. Creating our main MyApp class extends with State StatelessWidget. In this class we are calling GetDate() class.

4. Creating a class named as GetDate extends StatefulWidget. In this class we would make the createState() State method with _GetDateState() class name to enable mutable state management in given class tree.

5. Creating our main Child class named as _GetDateState extends State. This is our main class in which we would perform all the code to get current date in flutter.

6. Creating a variable named as finalDate with empty data. We would use this variable to store the final formatted date.

7. Creating a function named as getCurrentDate(). In this function we would first get the current date using DateTime class object. Now we would parse the date and now finally we would extract the current date, month and year and store in formattedDate variable. Now we would use the State method to set the formattedDate variable value to finalDate variable.

8. Creating Widget Build area in _GetDateState class. Now we would make 1 Text Widget and 1 Raised Button widget. We would set the current date in Text widget and call the getCurrentDate() function from Raised Button onPress event.

9. Complete source code for main.dart file:

Screenshots:

Flutter Get Current Date With Day Month Year Format Example Android iOS Tutorial

2 Comments

  1. i want date like this 👇
    27-04-2019

    double figure month
    how to do that????

  2. I want date like the following
    October 15, 2021

    How to do it?

Leave a Reply

Your email address will not be published.