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()

Categories

HOME
path-finding
plone
comparison
view
xmpp
spring-cloud-stream
amazon-ecs
jsrender
applepay
facebook-php-sdk
ssl-client-authentication
user-input
midi
windows-azure-storage
timeout
circuit
progressive-web-apps
propel
undefined
swingx
amazonsellercentral
graphicsmagick
kvc
vlsi
internet-explorer-9
traffic
nhapi
buck
saas
fog
catch-all
gammu
google-api-nodejs-client
mapbox-gl
force-layout
devextreme
swift3.0.2
withings
objectlistview
hilbert-curve
ansible-playbook
particles.js
reportingservices-2005
quadratic-programming
wso2carbon
fault
jquery-nestable
brightcove
jxcore
slickedit
akka-cluster
mcafee
titanium-android
chord-diagram
background-service
visual-c++-2008
android-fonts
instant
gridpane
asp.net-4.5
nsfilemanager
xml-attribute
actionbardrawertoggle
uid
intellij-14
cyclomatic-complexity
0xdbe
cakephp-3.1
ideamart
arcanist
directoryservices
fscommand
xc16
gui-test-framework
java.util.concurrent
phalanger
device-manager
internet-connection
android-radiobutton
mysql-error-1062
mechanize-ruby
balanced-payments
ember-charts
tws
hamiltonian-cycle
labwindows
jspinclude
gwt-ext
appendto
propagation
dentrix
compiler-specific
msdev
data-acquisition
windows-live-messenger
ajax-forms

Resources

Encrypt Message