如何使用 JVM 参数为 java.util.Calendar 指定 firstDayOfWeek [英] How to specify firstDayOfWeek for java.util.Calendar using a JVM argument

查看:29
本文介绍了如何使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆