Dart解析日期为+0000 [英] Dart parse date with +0000

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

问题描述

我正在使用Twitter api在Flutte App中获取推文。
api返回如下格式的日期:

I am using the Twitter api for getting tweets in a Flutte App. The api returns a formatted date like this:

星期三6月12日00:08:35 +0000 2019

  DateTime formatTwitterDate() {
    final format = DateFormat('EEE MMM dd hh:mm:ss +0000 yyyy'); //todo failed to resolve +0000
    return format.parse(this);
  }

这是我唯一使用的格式化程序。我如何支持+0000?

This is the only formatter I got working. How can I support +0000?

推荐答案

移植对dart的答案

Porting this answer to dart

  var s = "Fri Apr 09 12:53:54 +0000 2010";
  print(s);

  final newString =
      s.replaceAllMapped(RegExp(r'\w+ (\w+) (\d+) ([\d:]+) \+0000 (\d+)'), (m) {
    return "${m[1]} ${m[2]} ${m[4]} ${m[3]} UTC";
  });
  print(newString);

这篇关于Dart解析日期为+0000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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