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


基础教程推荐
- 大摇大摆的枚举 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01