java 如何在java中设置日期1/1/1753

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13757675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 13:53:28  来源:igfitidea点击:

How to set date 1/1/1753 in java

javacalendar

提问by Rohit Elayathu

I am using following code to set currebnt date-

我正在使用以下代码设置当前日期-

session.getCurrentDate().getTime()

Now i want to set the minimum date ie- 1/1/1753, is there any constant or function for doing this other than explicitly hardcoding it.

现在我想设置最小日期,即 1/1/1753,除了明确地对其进行硬编码之外,是否有任何常量或函数可以执行此操作。

回答by Murali Prasanth

do this

做这个

Calendar c1 = GregorianCalendar.getInstance();
  c1.set(1753, Calendar.JANUARY, 01);  //January 1st 1753

回答by Abubakkar

I think you want a default date to be set.

我认为您希望设置默认日期。

I would create a String and then simply parse it to get the required date.

我会创建一个字符串,然后简单地解析它以获得所需的日期。

SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
Date myDefaultDate = format.parse("1/1/1753");

Now myDefaultDatewill contain the date "1/1/1753".

现在myDefaultDate将包含日期“1/1/1753”。

回答by Patricia Shanahan

The default is the current time - see the parameterless constructor.

默认值为当前时间 - 请参阅无参数构造函数。

The switch to the Gregorian calendar happened on different dates. The GregorianCalendar class uses October 4, 1582, the date the first group of countries changed over, as the default change date.

改用公历发生在不同的日期。GregorianCalendar 类使用 1582 年 10 月 4 日,即第一组国家更改的日期,作为默认更改日期。

You can obtain the default change date using new GregorianCalendar().getGregorianChange().

您可以使用 获取默认更改日期new GregorianCalendar().getGregorianChange()

That is not the earliest possible date because GregorianCalendar uses the Julian calendar before the change over. In any case, the calendar is projected both into the past, even before creation of the Julian calendar, and into the future.

这不是最早的可能日期,因为 GregorianCalendar 在更改之前使用儒略历。在任何情况下,日历都被投影到过去,甚至在儒略历创建之前,也被投影到未来。