How to specify firstDayOfWeek for java.util.Calendar using a JVM argument(如何使用 JVM 参数为 java.util.Calendar 指定 firstDayOfWeek)
问题描述
我正在尝试将 java.util.Calendar 的默认 firstDayOfWeek 从 SUNDAY 更改为 MONDAY.是否可以通过JVM配置而不是添加这段代码来实现?
I'm trying to change default firstDayOfWeek for java.util.Calendar from SUNDAY to MONDAY. Is it possible to achieve this through JVM configuration instead of adding this piece of code?
cal.setFirstDayOfWeek(Calendar.MONDAY);
推荐答案
一周的第一天派生自当前语言环境.如果您没有设置日历的区域设置 (Calendar.getInstance(Locale),或 new GregorianCalendar(Locale)),它将使用系统的默认值.系统的默认值可以被 JVM 参数覆盖:
The first day of the week is derived from the current locale. If you don't set the locale of the calendar (Calendar.getInstance(Locale), or new GregorianCalendar(Locale)), it will use the system's default. The system's default can be overridden by a JVM parameter:
public static void main(String[] args) {
Calendar c = new GregorianCalendar();
System.out.println(Locale.getDefault() + ": " + c.getFirstDayOfWeek());
}
这应该显示具有不同 JVM 参数的不同输出:
This should show a different output with different JVM parameters for language/country:
-Duser.language=en -Duser.country=US
->en_US: 1
(星期日)-Duser.language=en -Duser.country=GB
->en_GB: 2
(星期一)
不要忘记这也可能改变其他行为.
Don't forget that this could change other behavio(u)r too.
这篇关于如何使用 JVM 参数为 java.util.Calendar 指定 firstDayOfWeek的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 JVM 参数为 java.util.Calendar 指定 firstDay


- Eclipse 的最佳 XML 编辑器 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 转换 ldap 日期 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 获取数字的最后一位 2022-01-01