日期时间波动 [英] DateTime Flutter

查看:66
本文介绍了日期时间波动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将当前时间实现为文本格式?我觉得这应该很简单,但是很难做到。



基本示例;



解决方案


How do I implement the current time into Text format? I feel like it should be fairly simple but struggling to do so.

Basic example;

解决方案

Using the answer here and changing it a bit:-

You can try the following:

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';



void main() {
 runApp(TabBarDemo());
}

class TabBarDemo extends StatelessWidget {
 @override
Widget build(BuildContext context) {
DateTime now = DateTime.now();
String formattedDate = DateFormat('kk:mm:ss \n EEE d MMM').format(now);
return MaterialApp(
  home: DefaultTabController(
    length: 3,
    child: Scaffold(
      appBar: AppBar(
        bottom: TabBar(
          tabs: [
            Tab(icon: Icon(Icons.access_alarm),text: "Alarm",),
            Tab(icon: Icon(Icons.access_time),text:"Clock" ,),
            Tab(icon: Icon(Icons.timer),text:"Timer"),
          ],
        ),
        title: Text('Tabs Demo'),backgroundColor: Colors.black,
      ),
      body: TabBarView(
        children: [
          Icon(Icons.access_alarm),
          Center(child: Text(formattedDate,textAlign: TextAlign.center,style: new TextStyle(fontWeight: FontWeight.bold,fontSize: 25.0),)),
          Icon(Icons.timer),
        ],
      ),
    ),
  ),
);
}
}

Should give you this:

这篇关于日期时间波动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆