以与系统相同的格式获取系统日期 [英] get the system date in the same format as the system
本文介绍了以与系统相同的格式获取系统日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望我的Java程序采用系统日期格式.
I want my java program to take the system date format .
例如:当我将系统中的日期格式从 mm-dd-yy
更改为 yyyy-MM-dd
时.我希望我的Java程序从系统中提取短日期格式并显示在程序中.
Ex: when i change the date format in the system from mm-dd-yy
to yyyy-MM-dd
.
I want my java program to pull the short date format from the system and display in my program.
同样,如果我将系统格式更改为 M/D/YY
,我的Java程序将显示此格式.
Again if I change the system format to M/D/YY
, my java program to display this.
我尝试了几种选择,
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat();
System.out.println(System.currentTimeMillis());
System.out.println(cal.getTime());
System.out.println( sdf.format(cal.getTime()) );
尽管系统中具有 yyyy-mm-dd
格式,但这始终会打印 mm/dd/yy
.
this always prints mm/dd/yy
inspite of having yyyy-mm-dd
format in the system.
任何帮助将不胜感激.
推荐答案
返回描述此日期格式的本地化模式字符串.
Returns a localized pattern string describing this date format.
这篇关于以与系统相同的格式获取系统日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文