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


基础教程推荐
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01