Ayfri
12/02/2021, 3:45 PMval versionDate = "May 5, 2009"
val formattedDate = SimpleDateFormat("MMM d, yyyy").parse(versionDate)
println(formattedDate)
What am I doing wrong ?Kirill Grouchnikov
12/02/2021, 3:47 PMKirill Grouchnikov
12/02/2021, 3:47 PMAyfri
12/02/2021, 3:49 PMRob Elliot
12/02/2021, 3:51 PMimport java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.Locale.ENGLISH
val versionDate = "May 5, 2009"
val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("MMM d, yyyy", ENGLISH)
LocalDate.parse(versionDate, formatter)
Rob Elliot
12/02/2021, 3:52 PMSimpleDateFormat
is not threadsafe, which has bitten thousands of people who thought they could use it safely across threads. And Date
(which is what it returns) & its companion Calendar
are considered some of the worst designed classes of all time.ribesg
12/02/2021, 3:52 PMMay
Ayfri
12/02/2021, 3:52 PMAyfri
12/02/2021, 3:53 PMribesg
12/02/2021, 3:54 PMribesg
12/02/2021, 4:00 PMjava.time
, SimpleDateFormat is like 25 years old or something)Ayfri
12/02/2021, 4:02 PMjava.time
Rob Elliot
12/02/2021, 4:03 PMAyfri
12/02/2021, 4:03 PMAyfri
12/02/2021, 4:05 PMRob Elliot
12/02/2021, 4:07 PMMay 15, 2009
ribesg
12/02/2021, 4:09 PMNumber: […] For parsing, the number of pattern letters is ignored unless it’s needed to separate two adjacent fields.
ribesg
12/02/2021, 4:10 PMdd
if you wanted to format 5
to 05
, but for parsing there is no reason to use more than d
Colton Idle
12/03/2021, 3:08 PM