tl;dr
LocalDateTime.parse( "2011/06/13 17:52:20".replace( " " , "T" ) )
.isBefore( LocalDateTime.now() )
true
Details
The other Answers are correct in that you can either (a) alphabetically compare those particular strings, or (b) chronologically compare after parsing into date-time objects.
And be aware that date-time formats do not have a “format”. They contain date-time information. They can generate a String that is in a particular format, but the date-time object and the string are separate and distinct.
The other Answers use the troublesome old date-time classes that are now legacy, supplanted with the java.time classes.
Your inputs lack info about offset-from-UTC and time zone. So we must parse them as LocalDateTime
objects. To parse, replace the SPACE in the middle with a T
to comply with the ISO 8601 standard for formatting strings that represent date-time values.
String input = "2011/06/13 17:52:20".replace( " " , "T" );
LocalDateTime ldtThen = LocalDateTime.parse( input ) ;
LocalDateTime ldtNow = LocalDateTime.now( ZoneId.of( "America/Montreal" ) ) ;
Compare.
boolean ldtThenIsBefore = ldtThen.isBefore( ldtNow );
boolean ldtThenIsAfter = ldtThen.isAfter( ldtNow );
boolean ldtThenIsEqual = ldtThen.isEqual( ldtNow );
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more.