How can i convert date of type dd.mm.yy
to dd/mm/yy
?
i'm using Selenium + Java
Thanks
How can i convert date of type dd.mm.yy
to dd/mm/yy
?
i'm using Selenium + Java
Thanks
If you are using java.util.Date
:
SimpleDateFormat dateTimeFormatter = new SimpleDateFormat("dd.MM.yy");
Date unformattedDate = dateTimeFormatter.parse("your date here");
dateTimeFormatter = new SimpleDateFormat("dd/MM/yy");
String formattedDate = dateTimeFormatter.format(unformattedDate);
This is a legacy package and the below code is recommended
If you are using java.time.*
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd.MM.yy");
LocalDate unformattedDate = LocalDate.parse("your date here", dateTimeFormatter);
dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yy");
String formattedDate = dateTimeFormatter.format(unformattedDate);
And I would make the following change to your pattern. Instead of using y
I would use u
for the year since it also covers AD
and BC
.
Example: dd/MM/uu
.
For more refer to this.