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

Not able to create Maven Project in Eclipse
Read specific characters from specific line of text in java
Executing code every x seconds
Attempting (and failing) to create user function for H2 database
Android Studio crash on findViewById
Remove Specific Component from JPanel - Java
can we create object of abstract class?
Use entityManager to save into two tables with FK in one of the tables
Is it a bad practice to have database calls in Filter classes?
How to invoke cmd commands in from a Java program in Windows?
JAXB generates class twice for complextype and element ref from XSD
File input, String manipulation and output
No suitable driver when trying to create SQL database [duplicate]
Converting for loop to while loop in Java
Reversing hash function in java
Trouble displaying toolbar from activity using fragments

Categories

HOME
log4j
bluetooth
asp.net-core
cookies
reserved
google-play
plot
hashmap
dot
sqlite-net-extensions
react-redux
leon
rubygems
rdf
twitter-bootstrap-4
umd
google-project-tango
callback
ios-charts
node-notifier
esper
primary-key
postgres-xl
decimal
quartz-scheduler
foselasticabundle
django-admin
facebook-page
samoa
introduction
java-3d
opencover
dcevm
extjs5
mustache.php
core-text
crystal-reports-2010
smb
microsoft-sync-framework
qhull
brunch
elasticsearch-net
ejabberd-module
gitignore
unboundid
directx-10
phonegap
usbserial
xcode-extension
libraries
starteam
objectlistview
webix-treetable
ssjs
uft-api
bootstrapper
cookiecutter-django
glew
heightmap
thin
youcompleteme
drupal-6
python-cryptography
pillow
cudafy.net
lync-client-sdk
blacklist
heidisql
passport-google-oauth
azure-virtual-network
ctest
qpid
clang-static-analyzer
sigabrt
revolution-r
associative-array
phpcas
jfugue
drawbitmap
tableau-online
event-bubbling
createprocessasuser
vstest.console.exe
dereference
bridge.net
javax.mail
csquery
tablelayout
coldbox
angularjs-ng-click
asp.net-web-api-odata
gulp-less
markers
googlemock
sgen
valuechangelistener
hippomocks
farseer
ril
anonymous-methods
simba
tridion-worldserver
whoosh
genshi
sql-server-profiler
html-input
digest-authentication
grid-system

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