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

How to disable button for 3 seconds in java
How To Improve Quality of audio for Live Audio Streaming applicatio in java
How to make sure that NullPointerException doesn't come while showing infinite data from api.
knowing when job is crashed (or listen to a job stoppage)
Flink Streaming: window never finalised
ElasticSearch - Access denied when trying to restore a backup (type = url)
Detecting corners and angle of object at image using OpenCV defined by small squares? [closed]
Can java String.format handle replacing ? instead of %s
Add a Method to Object Array
Map alternative for primitive values
Check if value entered exists in database android
add listener for javafx textField upto 2 decimal place
Using javax.jws.WebParam to have more the one WebParam in different xml sub tag
Using Hibernate to Query Range from 2 Different property
BST - counting nodes with left and right children
xdocconverter ODT to pdf ArrayIndexOutOfBoundsException

Categories

HOME
multithreading
client
smarty
jxls
umd
acquia
flyway4
datastax-java-driver
azure-media-services
iggrid
gnupg
user-input
mapserver
leiningen
clojurescript
saxon
propel
beyondcompare
karma-jasmine
scichart
nas
swiftlint
object-detection
google-search-api
microsoft-r
crosstab
javacv
fish
poltergeist
intel-pin
nhapi
neo4j-spatial
socialengine
phonegap
kendo-ui-grid
stringtemplate
rotational-matrices
amazon-kinesis-kpl
fusionpbx
hue
elasticsearch-plugin
cookiecutter-django
http-live-streaming
ibpy
nomethoderror
.net-4.6.2
businessworks
appcompat
filepicker
upstart
pango
alphabet
integrity
togetherjs
colorama
pg-dump
libusb-win32
nested-sets
spring-android
android-textview
skobbler-maps
paypal-express
flash-cs5
ios4
sdhc
ruby-2.2
wireshark-dissector
pundit
security-testing
interrupted-exception
remobjects
clipperlib
sorl-thumbnail
clicktag
jsonpickle
codeigniter-routing
titanium-modules
websocket4net
onactivityresult
flask-cors
mesa
sgen
typo3-neos
page-layout
ms-project-server-2010
inbox
html4
padarn
sqlperformance
http-unit
kyotocabinet
free-variable
selected
viewswitcher
jspinclude
enter
php-parser
nsobject
deobfuscation
psi
lpeg
gallio
multi-tier
web-architecture
firefox4
javap
virtual-functions
swing-app-framework
xetex
thread-local-storage
scripting-languages
ubuntu-9.04
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