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

Entering multiple things in to one array in java
Android: TypedArray.recycle() - what does it do, why is it important?
Elasticsearch Java API Client
Add custom Analyzer implementation through Elasticsearch plugin
Adding a string to an ArrayList of strings in the JFrame after the button is pressed
How programatically (!) validate soap request/response with wsdl?
{solved} Maven ignoring the “maven-compiler-plugin” requirements
Loop through XML String using XPath - Java
Storing a KeyStore in Java: empty file and unable to reload
How to install log4j bundle into Eclipse?
Is there any way to force JAVA to print empty CDATA within Elements?
Slick2D AlphaMapTest Running
Creating a set of instances using a loop
Reading lines from System.In without an endline character
GoogleMap.setpadding() is undefined for the type GoogleMap
Android - add values to String[] through another class

Categories

HOME
xamarin
osgi
clips
mfc
iterator
onedrive
raspberry-pi
relayjs
electron
youtube-dl
kalman-filter
cvs
maven-3
jpeg
umd
onelogin
azure-media-services
commonmark
fortumo
apache-metamodel
connection-string
jprofiler
css-animations
kudan
microsoft-r
opennlp
tdd
large-file-upload
quote
lightswitch-2013
google-rich-snippets
junit5
geopositioning
mapbox-gl
host
swisscomdev
dynamics-crm-2013
az-application-insights
uft-api
sas-visual-analytics
ws-security
ensembles
ncalc
firebase-admin
nand2tetris
mime
total-commander
websphere-mq-fte
datastax-startup
gabor-filter
lift-json
crypt
qtwebview
hittest
lync-client-sdk
minimization
chord-diagram
httplistener
persist
blackberry-10
ubuntu-10.04
testng-dataprovider
bgp
apachebench
phpcas
pervasive-sql
xna-4.0
ibaction
interrupted-exception
truevault
oxwall
knuth
qcodo
nsbutton
xcode-6.2
elliptic-curve
hippomocks
jboss-weld
meteor-velocity
app42
html5-notifications
runtime.exec
dataadapter
factory-method
browser-detection
unc
bitsharp
boost-filesystem
qt-jambi
locationlistener
krl
celltable
datareader
telerik-scheduler
digest-authentication
paster
sortable-tables
gallio
rescale
noscript
putchar
defensive-programming

Resources

Encrypt Message