Class Date (2.57.0)

Beta

This library is covered by thePre-GA Offerings Terms of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see thelaunch stage descriptions.

publicfinalclassDateimplementsComparable<Date>,Serializable

Represents a Date without time, such as 2017-03-17. Date is timezone independent.

Inheritance

Object >Date

Static Methods

fromJavaUtilDate(Date date)

publicstaticDatefromJavaUtilDate(Datedate)

Convert a Java Util Date to a Google Date.

Parameter
NameDescription
dateDate

the date of the java.util.Date

Returns
TypeDescription
Date

Google Java Date

fromYearMonthDay(int year, int month, int dayOfMonth)

publicstaticDatefromYearMonthDay(intyear,intmonth,intdayOfMonth)

Constructs a new Date instance.

Parameters
NameDescription
yearint

must be greater than 0

monthint

must be between [1,12]

dayOfMonthint

must be between [1,31]

Returns
TypeDescription
Date

parseDate(String date)

publicstaticDateparseDate(Stringdate)
Parameter
NameDescription
dateString

Data in RFC 3339 date format (yyyy-mm-dd).

Returns
TypeDescription
Date

toJavaUtilDate(Date date)

publicstaticDatetoJavaUtilDate(Datedate)

Convert a Google Date to a Java Util Date.

Parameter
NameDescription
dateDate

the date of the Google Date.

Returns
TypeDescription
Date

java.util.Date

Methods

compareTo(Date other)

publicintcompareTo(Dateother)
Parameter
NameDescription
otherDate
Returns
TypeDescription
int

equals(Object o)

publicbooleanequals(Objecto)
Parameter
NameDescription
oObject
Returns
TypeDescription
boolean
Overrides

getDayOfMonth()

publicintgetDayOfMonth()

Returns day of month between 1 and 31 inclusive.

Returns
TypeDescription
int

getMonth()

publicintgetMonth()

Returns the month between 1 and 12 inclusive.

Returns
TypeDescription
int

getYear()

publicintgetYear()

Returns the year.

Returns
TypeDescription
int

hashCode()

publicinthashCode()
Returns
TypeDescription
int
Overrides

toString()

publicStringtoString()
Returns
TypeDescription
String
Overrides

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-01-31 UTC.