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

Custom layout not working with List view (Single choice)
Android app using canvas in SurfaceView, pressing the recent apps button gives a laggy transition, how can this be changed?
Is there a general method of drawing 2d objects on a digital screen
Making a comparator between two results
Returns the minimum element in the list t , recursively
Selenium test case script with Junit is not working on eclipse for Firefox driver
How to shift an entire array one position to the right?
Sybase jdbc4 not returning any results from sql query
ClassNotFoundException in reading object from GZipped file
Dynamic-reports classpath
Cannot Input String
Android Shorten and encrypt Xml-Code
Read/Write from RandomAccessFile in Java
Do Java Mission Control and Flight Recorder deliver same functionality as VisualVM?
How to disable Apache JServ protocol service
How to handle cursor if it throws exception in EJBs

Categories

HOME
maven
ms-access
listview
pypi
zeromq
deezer
kde
mfc
raspberry-pi
iot
sql-server-2016
wamp
in-app-purchase
swagger-ui
paradox
session-variables
izpack
export-to-csv
etl
apache-cayenne
moonmail
progressive-web-apps
django-admin
code-review
kryo
cx-freeze
autoconf
opencover
autosys
java-7
elasticsearch-net
flink-streaming
frame
binary-data
scorm2004
mozilla
vxworks
qwerty
x11-forwarding
swift3.0.2
espeak
reportbuilder
lumberjack
mapzen
galen
avro4s
http-redirect
wptoolkit
apple-news
azure-application-gateway
sage-one
hls.js
kbuild
ifs
imanage
or-tools
gnome-shell-extensions
background-service
abcpdf9
nxt
rotativa
bonobo
django-debug-toolbar
gstreamer-0.10
clang-static-analyzer
connect-by
markojs
ubuntu-10.04
master-slave
qgraphicsview
sdf
packagist
associative-array
energy
srand
reactive-banana
comobject
django-unittest
feedback
wyam
emailrelay
tableau-online
arcanist
interrupted-exception
system32
notify
bridge.net
umbraco6
directoryservices
xc16
winddk
android-imagebutton
mdt
markers
googlemock
ember-charts
centos5
ivyde
spring-io
ruby-datamapper
dataadapter
comaddin
sabredav
venn-diagram
multipage
reddot
vdsp
gcj
hamachi
w3wp.exe
gallio
audio-capture
sustainable-pace
project-hosting
gacutil
defensive-programming
post-build

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App