首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在日历中使用SimpleDateFormat?

如何在日历中使用SimpleDateFormat?
EN

Stack Overflow用户
提问于 2011-04-11 21:11:51
回答 4查看 91.2K关注 0票数 70

我有GregorianCalendar实例,并且需要使用SimpleDateFormat (或者可以与calendar一起使用但提供所需的#fromat()功能的东西)来获得所需的输出。请,建议工作作为永久解决方案的好办法。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-04-11 21:16:30

试试这个:

代码语言:javascript
复制
Calendar cal = new GregorianCalendar();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
dateFormat.setTimeZone(cal.getTimeZone());
System.out.println(dateFormat.format(cal.getTime()));
票数 105
EN

Stack Overflow用户

发布于 2012-05-10 21:56:15

eQui的答案漏掉了一步

代码语言:javascript
复制
Calendar cal = new GregorianCalendar();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
#---- This uses the provided calendar for the output -----
dateFormat.setCalendar(cal); 
System.out.println(dateFormat.format(cal.getTime()));
票数 39
EN

Stack Overflow用户

发布于 2011-04-11 21:14:26

Calendar.getTime()返回可与SimpleDateFormat一起使用的日期。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5621825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档