java
Get current date in YYYY-MM-DD format in Java (Android) [duplicate]
This question already has an answer here: Month issue in SimpleDateFormat class 5 answers I am trying to get a Date object in the format YYYY-MM-DD representing the current system date. Below is my attempt: Date todayDate = Calendar.getInstance().getTime(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-mm-dd"); String todayString = formatter.format(todayDate); The values are as follows: todayDate: Mon May 15 16:24:47 GMT+01:00 2017 todayString: 2017-24-15 Having tried this a couple of times I noticed the todayString is not made up of YYYY-MM-DD but YYYY-[minutes][minutes]-DD. How might I get the current date in the YYYY-MM-DD format?
Change this: SimpleDateFormat formatter = new SimpleDateFormat("yyyy-mm-dd"); to this: SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); mm stands for the minutes, while MM (capitalized) stands for the month
Related Links
How to use MultithreadedTC to test multithreading application?
Cannot load more than one osm files at a time
Why can't I instantiate outside any method in java?
Store object with included list of objects in sqlite
How to take a sub string of a string in java depending on both character
How to access a file inside a zipped war file without using Java zip utils?
Java String index out of bound
couchbase java client 1.2.* fails with maven dependency
Java write byte[] to file - empty file
read from mysql database,why chinese character can read by this
How to make multiple buttons centered to 3 different images and onClick not working
Mac Mavericks Java unable to locate executable bash_profile edits have not worked
onActivityResult() method called too early for starting call activity?
How to put the content of a JDom document into a File object?
Remote EJB Access using the EJB client jar
Troubleshooting ClassLoader.getResourceAsStream() or Class.getResourceAsStream()