Monday 18 February 2019

java - How does the Date type get the 'YY-MM-DD'?

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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...