Android的SimpleDateFormat的,如何使用它? [英] Android SimpleDateFormat, how to use it?
本文介绍了Android的SimpleDateFormat的,如何使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用Android的SimpleDateFormat是这样的:
I am trying to use the Android SimpledateFormat like this:
String _Date = "2010-09-29 08:45:22"
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
try {
Date date = fmt.parse(_Date);
return fmt.format(date);
}
catch(ParseException pe) {
return "Date";
}
}
结果是好的,我有:2010-09-29
The result is good and i have: 2010-09-29
但是,如果我改变的SimpleDateFormat到
But if i change the SimpleDateFormat to
SimpleDateFormat("dd-MM-yyyy");
问题是,我会得到03-03-0035 !!!!
the problem is that I will got 03-03-0035 !!!!
为什么和如何得到像DD-MM-YYYY格式
Why and how to get the format like dd-MM-yyyy
推荐答案
我想你想扭转日期格式?
I assume you would like to reverse the date format?
的SimpleDateFormat可用于解析和格式化。 你只需要两种格式,一种解析字符串和其他返回所需的打印输出:
SimpleDateFormat can be used for parsing and formatting. You just need two formats, one that parses the string and the other that returns the desired print out:
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
Date date = fmt.parse(dateString);
SimpleDateFormat fmtOut = new SimpleDateFormat("dd-MM-yyyy");
return fmtOut.format(date);
这篇关于Android的SimpleDateFormat的,如何使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文