如何获得完整的日期与正确的格式? [英] How to get full date with correct format?

查看:135
本文介绍了如何获得完整的日期与正确的格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得的日期。

我使用该日期和月份

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());

这篇关于如何获得完整的日期与正确的格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆