【发布时间】:2021-08-15 01:44:50
【问题描述】:
我最近开始使用 Flutter,我喜欢它的工作原理。我需要为我工作的公司创建一个适用于 iOS 和 Android 的应用程序,所以我开始使用 Flutter。
我们的网站使用 Wordpress,所以我尝试将其用作应用程序的后端。
一切顺利Ok 并且在应用程序中我有一个新闻部分,所以我编写了一些代码并进行了 Wordpress API 调用而且效果很好!
我只有一个问题:date 和 time 格式错误。我们在欧洲,所以我们使用dd-mm-yyyy 格式,在我的应用程序中,格式是这样的:yyyy-mm-dd,我需要更改它,但我不知道如何...
我的代码:
class Post {
final int id;
final String title;
final String author;
final String excerpt;
final String date;
final String content;
final String image;
bool isSaved = false;
Post(
{
this.content,
this.id,
this.title,
this.excerpt,
this.date,
this.image,
this.author,
}
);
factory Post.fromJSON(Map<String, dynamic> json) {
return Post(
id: json['id'],
title: json['title']['rendered'],
content: json['content']['rendered'],
date: json['date'] != null
? json['date'].toString().replaceFirst('T', ' ')
: null,
image: json['_links']['wp:featuredmedia'] != null
? json['_links']['wp:featuredmedia'][0]['href']
: null,
excerpt: json['excerpt']['rendered'],
author: json['author'].toString()
);
}
}
有人可以帮我看看吗?
谢谢!
【问题讨论】:
-
这能回答你的问题吗? How do I format a date with Dart?
标签: wordpress api flutter dart