如何获得完整的日期与正确的格式?如何获得、正确、完整、日期

2023-09-06 05:35:02 作者:klss黑色

我想获得的日期。

我使用该日期和月份

int date = cld.get(Calendar.DATE);
int month = cld.get(Calendar.MONTH);

相反,它返回一个INT我想这是一个字符串

。或者完整的日期格式。

Instead of it returning as a int i want it to be a string. or maybe the full date format.

如:12年12月12日 或...

Such as: 12/12/12 or...

2011年8月14日

August 14 2011

如何,我会去这样做?

推荐答案

您想了解的SimpleDateFormat

基础知识获取的当前时间ISO8601格式为:

The basics for getting the current time in ISO8601 format:

DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ");
String now = df.format(new Date());

对于其它的格式:

For other formats:

DateFormat df = new SimpleDateFormat("MMM d, yyyy");
String now = df.format(new Date());

DateFormat df = new SimpleDateFormat("MM/dd/yy");
String now = df.format(new Date());