The other Answers are correct.
java.time
Both the Question and other Answers use old date-time classes now outmoded by the java.time framework built into Java 8 and later. The old classes have proven to be poorly designed, confusing, and troublesome.
In the new classes, LocalDate
represents a date-only value without time-of-day and without time zone.
LocalDate localDate = LocalDate.of( 2014 , 0 , 1 );
We can apply a time zone while asking for the first moment of the day. That first moment is not always the time 00:00:00.0
so we should ask rather than assume.
The resulting ZonedDateTime
is an actual moment on the timeline.
ZoneId zoneId = ZoneId.of( "Europe/Paris" );
ZonedDateTime zdt = localDate.atStartOfDay( zoneId );
You can adjust to yet another time zone.
ZoneId zoneIdSaoPaulo = ZoneId.of( "America/Sao_Paulo" );
ZonedDateTime zdtSaoPaulo = zdt.withZoneSameInstant( zoneIdSaoPaulo );
Converting between legacy and modern classes
Best to avoid the legacy classes if possible. But if you must have an object of that class to interoperate with old code not yet updated for java.time, you can convert.
Calendar c = GregorianCalendar.from( zdtSaoPaulo ) ;
Going the other direction.
if( myCalendar instanceof GregorianCalendar )
{
ZonedDateTime zdt = ( ( GregorianCalendar ) myCalendar ).toZonedDateTime() ;
}
Similarly, you can go between legacy java.util.Date
and modern Instant
. And java.sql.Date
and LocalDate
.