DateTime的国际化无效

时间:2018-04-26 05:47:07

标签: datetime internationalization flutter

我有一个演示应用,国际化无法正常工作。 我的时间码是+3(北塞浦路斯)。语言是TR。日期部分适用于TR。 但时间不起作用。示例而不是显示08:27:18它显示格林威治标准时间05:27.18。

更多信息:https://greenwichmeantime.com/time-zone/europe/turkey/

示例:https://github.com/NTMS2017/Internationalization

请帮忙吗?

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

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

class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        return new MaterialApp(
            title: 'Internationalization',
            theme: new ThemeData(
                primarySwatch: Colors.blue,
            ),
            home: new MyHomePage(title: 'Internationalization'),
        );
    }
}

class MyHomePage extends StatefulWidget {
    MyHomePage({Key key, this.title}) : super(key: key);

    final String title;

    @override
    _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
    DateFormat dateFormat;
    DateFormat timeFormat;

    @override
    void initState() {
        super.initState();
        initializeDateFormatting();
        dateFormat = new DateFormat.yMMMMd('tr_TR');
        timeFormat = new DateFormat.Hms('tr_TR');
    }

    void _refresh() {
        setState(() {});
    }

    @override
    Widget build(BuildContext context) {
        var dateTime = new DateTime.now();
        return new Scaffold(
            appBar: new AppBar(
                title: new Text(widget.title),
                backgroundColor: Colors.pinkAccent,
            ),
            body: new Center(
                child: new Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                        new Text(dateFormat.format(dateTime),
                            style: new TextStyle(
                                fontSize: 24.0,
                                fontWeight: FontWeight.bold,
                                    color: Colors.pinkAccent,
                            ),
                        ),
                        new Text(timeFormat.format(dateTime),
                            style: new TextStyle(
                                fontSize: 22.0,
                                    fontWeight: FontWeight.bold
                            ),
                        ),
                    ],
                ),
            ),
            floatingActionButton: new FloatingActionButton(
                onPressed: _refresh,
                tooltip: 'Refresh',
                child: new Icon(Icons.refresh),
            ),
        );
    }
}

1 个答案:

答案 0 :(得分:0)

随着@GünterZöchbauer的帮助。我检查我的android模拟器。

我的模拟器是Nexus 5X API 26。 将模拟器语言设置为TR,将Region设置为Turkey,上面的代码运行良好。