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

List<Cluster<DoublePoint>> to Set<DoublePoint>
How to extend Lucene's StandardAnalyzer for custom special character treatment?
How to do sum of the numbers displayed on webpage in selenium webdriver with java
hibernate/hsqldb: Database file not found after shutdown
Checking on hidden class with jsoup
Is sessionCreated() from a HttpSessionListener automatically synchronized with request.getSession()?
Java NIO Sockets clients request processing
Spark DataSet: calculate stats and make sample on single pass
How to add an ArrayList to a Hashmap in Java
Java UML editable component/lib
IntelliJ IDEA: Best way to work on a project and on its dependency
JTextArea wont “.paint” to the correct location on screen
Why does my program not count every duplicate number in a certain list, but works for all others
Cordova Android JDK Requirement
Docker & Excelsior JET
Why am i getting a JPQL NullPointerException and how do i fix it?

Categories

HOME
twitter
hook
gremlin
kde
path-finding
electron
android-4.4-kitkat
youtube-dl
react-redux
electronics
windows-server
ravendb
mouse
podio
maude-system
quicklook
export-to-csv
nstableview
collectd
alignment
hapi
designer
solaris-10
oracle-coherence
visual-composer
textfield
amazonsellercentral
ml
jquery-ajaxq
tar
css-animations
hammerspoon
chromebook
bootstrap-material-design
nhapi
jspm
kendo-datasource
bluestacks
gtrendsr
environment-modules
git-merge
scaffold
swift3.0.2
mixture-model
android-browser
leading-zero
eclipse-scout
jvm-languages
node-sass
auto-update
azure-application-gateway
youcompleteme
jquery-nestable
theming
statsd
mplayer
setter
diagnostics
knockout-components
r-forge
akka-cluster
android-textview
slicknav
sts-springsourcetoolsuite
pcf
paypal-express
moveit
fadeout
revolution-r
uid
prerequisites
sdhc
interrupted-exception
nsight
dundas
offloading
.aspxauth
spring-io
apc
easy-install
ora-00911
dataadapter
qt-faststart
sharp-repository
smtp-auth
factory-method
unc
bitsharp
dsn
dbproviderfactories
cufon
whoosh
nsobject
psi
xmemcached
javax.script
netbeans-7.1
celltable
oncheckedchanged
lpeg
dbal
ext3
bespin
geneva-server
signal-handling
misv

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