我有GregorianCalendar实例,并且需要使用SimpleDateFormat (或者可以与calendar一起使用但提供所需的#fromat()功能的东西)来获得所需的输出。请,建议工作作为永久解决方案的好办法。
发布于 2011-04-11 21:16:30
试试这个:
Calendar cal = new GregorianCalendar();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
dateFormat.setTimeZone(cal.getTimeZone());
System.out.println(dateFormat.format(cal.getTime()));
发布于 2012-05-10 21:56:15
eQui的答案漏掉了一步
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()));
发布于 2011-04-11 21:14:26
Calendar.getTime()返回可与SimpleDateFormat一起使用的日期。
https://stackoverflow.com/questions/5621825
复制相似问题