Flutter Show Current Timestamp Example

28-Mar-2022

.

Admin

Flutter Show Current Timestamp Example

Hi friends,

In this post, we will learn how to show current timestamp in flutter Code Example. i explained simply step by step How to Get Timestamp in Dart/Flutter. Here you will learn Simple how to obtain current timestamp in flutter code / Ingrom. This tutorial will give you simple example How to show Current Date in Flutter.

I will give you simple Example of how to show current timestamp in flutter.

So let's see bellow example:

import 'package:flutter/material.dart';

import 'dart:async';

void main () => runApp(MyApp());

class MyApp extends StatelessWidget{

@override

Widget build(BuildContext context) {

return MaterialApp(

theme: ThemeData(primarySwatch: Colors.red),

home: FlutterTimeDemo(),

);

}

}

class FlutterTimeDemo extends StatefulWidget{

@override

_FlutterTimeDemoState createState()=> _FlutterTimeDemoState();

}

class _FlutterTimeDemoState extends State

{

late String _timeString;

@override

void initState(){

_timeString = "${DateTime.now().hour} : ${DateTime.now().minute} :${DateTime.now().second}";

Timer.periodic(Duration(seconds:1), (Timer t)=>_getCurrentTime());

super.initState();

}

@override

Widget build(BuildContext context) {

return Scaffold(

appBar: AppBar(title: Text('Display Current Timestamp'),),

body:Center(

child: Text(_timeString, style: TextStyle(fontSize: 30),),

),

);

}

void _getCurrentTime() {

setState(() {

_timeString = "${DateTime.now().microsecondsSinceEpoch}";

});

}

}

Output


I hope it will help you....

#Flutter