Den*_* S. 67 java formatting calendar date simpledateformat
我有GregorianCalendar实例,需要使用SimpleDateFormat(或者可以用于日历,但提供所需的#fromat()功能)以获得所需的输出.请建议解决方案和永久解决方案一样好.
jan*_*ink 95
试试这个:
Calendar cal = new GregorianCalendar();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
dateFormat.setTimeZone(cal.getTimeZone());
System.out.println(dateFormat.format(cal.getTime()));
Run Code Online (Sandbox Code Playgroud)
Jam*_*ton 34
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()));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
81914 次 |
最近记录: |