国际包装和日期格式奇怪的行为 [英] intl package and date formatting strange behaviour

查看:205
本文介绍了国际包装和日期格式奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在我的dart项目中使用intl包.开始使用此程序包后,我将使用以下代码:

I start to use intl package in my dart project. After start to use this package i use this code:

  DateTime now = new DateTime.now();
  var formatter = new DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
  String nowFormatted = formatter.format(now);

它可以正常工作.使用intl后,我会在日志中获得以下消息:

And it works correctly. After i use intl i obtain this message in log:

Uncaught LocaleDataException: Locale data has not been initialized, call initializeDateFormatting(<locale>).

我不明白为什么我应该在此代码段中传递语言环境

I cannot understand why i should pass locale in this code snippet

推荐答案

intl:^ 0.15.7

我对当前的 Intl 版本有相同的问题,所以我已经解决了

intl: ^0.15.7

I've the same issue to the current Intl version so I've solved with

这些进口:

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

和代码:

initializeDateFormatting();
DateTime now = DateTime.now();
var dateString = DateFormat('dd-MM-yyyy').format(now);
final String configFileName = 'lastConfig.$dateString.json';

这篇关于国际包装和日期格式奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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