You can do it by the below code.
public void getCurrentTimeStampInYYMMDDFormat() {
String date = new SimpleDateFormat("yy-MM-dd").format(new Date());
}
If you are using JDK8 then, you can also do it like this:
public void getCurrentTimeStampInYYMMDDFormat() {
String date = LocalDateTime.now()
.format(DateTimeFormatter.ofPattern("yy-MM-dd"));
}
No comments:
Post a Comment