【发布时间】:2016-12-09 13:02:37
【问题描述】:
我想从给定的字符串中获取日期。假设我们有一个字符串 09-Dec-2016 12:00:00 AM 我只想显示 30-Dec-2016
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView=(TextView)findViewById(R.id.date);
// String strCurrentDate = "Wed, 18 Apr 2012 07:55:29 +0000";
String strCurrentDate = "30-Dec-2016 12:00:00 AM";
// SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss Z");
SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss Z");
Date newDate = null;
try {
newDate = format.parse(strCurrentDate);
} catch (ParseException e) {
e.printStackTrace();
}
format = new SimpleDateFormat("dd-MMM-yyyy hh:mm a");
String date = format.format(newDate);
textView.setText(date);
}
我想显示这样的日期 2016 年 12 月 30 日
【问题讨论】:
-
有谁能帮忙吗?
-
日期从 9 日更改为 30 日。那是一段时间旅行。
-
什么意思?
-
阅读你的问题......然后你就知道AlphaQ是什么意思......
-
用 AlphaQ 改了