【问题标题】:Convert Date to Simple Date notation将日期转换为简单日期表示法
【发布时间】:2018-12-18 07:48:15
【问题描述】:

我正在使用 Twitter api。 我从 api 得到这个

"created_at": "2018 年 12 月 17 日星期一 21:37:27 +0000"

我怎样才能让它成为一个美好的约会,例如:

2017 年 12 月 17 日?

DateFormat outputFormat = new SimpleDateFormat("dd MMM yyyy");
DateFormat inputFormat = new SimpleDateFormat("????");
String inputDateStr = "Mon Dec 17 21:37:27 +0000 2018";
Date date = inputFormat.parse(inputDateStr);
String s = outputFormat.format(date);

有人可以帮我解决这个问题吗? 像“EE MMM dd H:m:s +0000 yyyy”之类的东西?

【问题讨论】:

标签: android date format


【解决方案1】:

这里给你答案

Kotlin 版本

val date = "Mon Dec 17 21:37:27 +0000 2018"
val dateFormat = "EEE MMM dd HH:mm:ss ZZZZZ yyyy"
val simpleDateFormat = SimpleDateFormat(dateFormat, Locale.ENGLISH)

val result = simpleDateFormat.parse(date)

Java 版本

String date = "Mon Dec 17 21:37:27 +0000 2018";
String dateFormat = "EEE MMM dd HH:mm:ss ZZZZZ yyyy";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat, Locale.ENGLISH);

Date result = simpleDateFormat.parse(date)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-20
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    • 2017-07-25
    • 1970-01-01
    相关资源
    最近更新 更多