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

Use Streams to return Boolean if all the List values in a Map are empty/not-empty
How to avoid the repeated code in java?
Is there any way to make the input from a scanner into an interface?
Compiling a program inside of another program [to a jar file?] [duplicate]
How do I let the user input the variable again after doing an error?
Unable to get Integer Value of Variable Stored in Java Thread Local Object
Java applet will not display in html file
Netflix archaius cannot read updated property file value
trouble with setTime method
JavaFX DatePicker: can it be Day and Month only, without Year?
Spring servletcontext cannot access bean in root application context
How to write a remove method?
Double dot notation no longer works out of classpth (out of bin when using eclipse) for Class.getResouce()?
Converting media content into string in Java
i want to putHeader to my url when timeout equal 5s but it error “java.lang.IllegalStateException: Response has already been written”
String replaceAll not working with string object [duplicate]

Categories

HOME
twitter
client
deployment
tinymce
at-command
rsync
jira
filtering
cmd
amazon-ecs
blueprintjs
python-unittest
floating-action-button
rascal
circuit
iron-router
clojurescript
jsdoc
propel
evopdf
extjs5
realex-payments-api
mmap
tibco-mdm
trading
smb
internet-explorer-9
linkerd
webkitspeechrecognition
titanium-mobile
protovis
bitbucket-pipelines
twitch
greenrobot-eventbus
optix
botbuilder
no-www
http-redirect
checkboxlist
angular2-meteor
btrace
osx-mavericks
multipeer-connectivity
worksheet
feeds
lync-client-sdk
background-service
yt-project
libpng
elements
fputcsv
simplewebrtc
sigabrt
associative-array
javax.sound.midi
ios8-today-widget
vhd
execute
sdhc
comobject
sframe
ideamart
sailfish-os
nsight
coldbox
sgen
balanced-payments
gnu-smalltalk
access-rights
spring-io
odata4j
gridcontrol
android-screen-support
lcs
distutils
gdata-api
nsmanagedobject
reddot
pendrive
cufon
fireworks
xmemcached
telerik-scheduler
h.323
virtual-functions
lzh

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile