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

JUnit failing from HeadlessException in program using java.awt/javax.swing
How to get name of subclass from an instance of the superclass placed in another class? [duplicate]
getcontentpane method in JFrame class
How testNG report is working internally when we implemented multi thread in class level?
Dynamically reference bundles for integration test with Pax Exam
Resource File Path as String (not streaming)
How to receive a file from a socket and not its content?
How does a developer interact with a 3D designer?
My app crashes when my phone's language is set to Persian or Arabic because of Double.parseDouble
Java 8 lambda adding to a list in a Hashmap, in a Hashmap
Time Service is not working.On Running it shows “Unfortunately Stopped”
JSON array and make it show on Android app
Switch on Enum does not import class
Why is #DiscriminatorColumn ignored when using #JoinTable?
How to retrieve the value of a text box and use it in the same page without redirecting to a next page in JSP?
Mastermind Game Algorithm

Categories

HOME
gitlab
asp.net-core
listview
hook
keras
reflection
plot
dot
read-eval-print-loop
jira
alpha
ezpublish
networkx
uber-api
adfs
facebook-php-sdk
orchardcms
iolanguage
django-simple-history
workload-scheduler
graphlab
normalizr
karma-jasmine
scichart
kvc
pepper
react-css-modules
nhapi
neo4j-spatial
gsmcomm
react-chartjs
azure-sql-database
gammu
rotational-matrices
hexo
bitbucket-pipelines
scaffold
event-driven
dynamics-crm-2013
android-fingerprint-api
document.write
bootstrapper
squib
sas-visual-analytics
node-sass
smartcontracts
pango
errordocument
hendrix
tizen-native-app
statsd
slickedit
libusb-win32
linode
mediaelement
migradoc
angular-strap
libpng
disque
qcustomplot
wapiti
kendonumerictextbox
xna-4.0
sdhc
eclipse-clp
pundit
arcanist
operation
android-nested-fragment
applescript-objc
aapt
system.net.webexception
undefined-reference
ember-charts
fmod
mcts
html5-notifications
web2py-modules
dataservice
cos
eventual-consistency
factory-method
chuck
enter
reddot
buildr
code-cleanup
punbb
assembly-loading
subscript
boost-filesystem
mercurial-server
f#-powerpack
infrastructure
getresponsestream
xsdobjectgen
virtual-functions
.net-1.0
misv





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