简体   繁体   中英

What's the difference from Calendar.DATE and Calendar.DAY_OF_MONTH?

Is there any difference when I called:

calendar.get(Calendar.DATE);
calendar.get(Calendar.DAY_OF_MONTH);
calendar.set(Calendar.DATE, day);
calendar.set(Calendar.DAY_OF_MONTH, day);

?

See the api doc for java.util.Calendar (emphasis mine):

public static final int DAY_OF_MONTH

Field number for get and set indicating the day of the month. This is a synonym for DATE. The first day of the month has value 1.

Synonym ” means a word with the same meaning. these two constants mean the same thing and are interchangeable.

Also if you look in the code, you'll notice these constants are defined with the same value:

/**
 * Field number for <code>get</code> and <code>set</code> indicating the
 * day of the month. This is a synonym for <code>DAY_OF_MONTH</code>.
 * The first day of the month has value 1.
 *
 * @see #DAY_OF_MONTH
 */
public final static int DATE = 5;

/**
 * Field number for <code>get</code> and <code>set</code> indicating the
 * day of the month. This is a synonym for <code>DATE</code>.
 * The first day of the month has value 1.
 *
 * @see #DATE
 */
public final static int DAY_OF_MONTH = 5;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM