在java中怎么显示系统的日期_如何在Java中设置尊重用户操作系统设置的日期和时间格式...

我在

Windows 7机器上运行我的

Java应用程序,我的区域设置设置为格式化日期为YYYY-mm-dd,时间为HH:mm:ss(例如“2011-06-20 07:50:28”) .但是当我使用DateFormat.getDateTimeInstance().格式来格式化我的日期时,我看不到,而是得到“2011年6月20日上午7:50:28”.我的客户将操作系统设置为显示日期的方式来格式化日期需要做些什么?

这是我的代码如下:

File selGameLastTurnFile = selectedGame.getLastTurn ().getTurnFile ();

Date selGameModifiedDate = new Date (selGameLastTurnFile.lastModified());

if (selectedGame.isYourTurn ()) {

gameInfo = Messages.getFormattedString ("WhoseTurnIsIt.Prompt.PlayTurn",//$NON-NLS-1$

FileHelper.getFileName (selGameLastTurnFile),DateFormat.getDateTimeInstance().format(selGameModifiedDate));

} else {

gameInfo = Messages.getFormattedString ("WhoseTurnIsIt.Prompt.SentTurn",//$NON-NLS-1$

selGameLastTurnFile.getName (),DateFormat.getDateTimeInstance().format(selGameModifiedDate));

}

Messages.getFormattedString调用使用MessageFormat将日期放入一个如下所示的句子:

Play the turn ‘QB Nat vs Ian 008’ (received 20-Jun-2011 7:50:28 AM)

但是,我的操作系统设置是按照上述格式设置日期,我预计会看到:

Play the turn ‘QB Nat vs Ian 008’ (received 2011-06-20 07:50:28)

我在这里搜索和其他Java编程网站,找不到答案,但这似乎是一件很明显的事情,想要做,我觉得我缺少一些明显的东西.

@H_@R_502_448@_20@

您不能在纯Java中执行此操作. Sun / Oracle无法使此系统独立.

.NET库的快速浏览给出了this page – 引用:

The user might choose to override some of the values associated with the current culture of Windows through the regional and language options portion of Control Panel. For example,the user might choose to display the date in a different format or to use a currency other than the default for the culture. If the CultureInfo.UseUserOverride property is set to true,the properties of the CultureInfo.DateTimeFormat object,the CultureInfo.NumberFormat object,and the CultureInfo.TextInfo object are also retrieved from the user settings.

如果您需要此功能,我建议您以系统依赖于Windows的方式执行此操作(例如,以@laz建议的方式访问Windows注册表).

@H_@R_502_448@_20@

@H_@R_502_448@_20@

相关文章

总结

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

如您喜欢交流学习经验,点击链接加入交流1群:1065694478(已满)交流2群:163560250

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值