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

All Postgres connections permanently idle after Tomcat restart
Json Array data not getting into the ArrayList
GlassFish server not running netbeans
Java turtle graphics user input
Objects, classes and functions
How to find the value(s) that is most distant from the average using a loop?
jackson is serializing to stars, not the ones in the sky
Force java.net.preferIPv4Stack to true
2 SQL Executes in one method
Is IBM WACs development framework or not?
I want to retreive the values of xml file by giving the path of xml file in the config.properties file
get error in for loop's body in java
Java generic interface hierarchy
How to specify column types in a google drive file?
Java Error “This method must return a result of type string” occurs without reason
Firefox Webdriver unable to launch with extension

Categories

HOME
yii2
jdo
oracle11g
azure-data-factory
view
fft
sqlite-net-extensions
spring-cloud-stream
google-oauth
jgroups
baqend
append
slick-slider
collectd
jplayer
iron-router
workload-scheduler
django-cms
introduction
cx-freeze
buildbot
selectedindexchanged
url-scheme
brunch
traffic
entitlements
maxmind
spring-mybatis
typo3-6.2.x
libuv
stormpath
key-value-observing
preg-match-all
grails-3.1
stringtemplate
stacked
gesture
abstract-class
document.write
graphenedb
preconditions
mapzen
ncalc
midl
turbogears
slick-3.0
skeleton-css-boilerplate
angular-resource
boost-multi-index
sage-one
statsd
recursive-datastructures
darcs
slickedit
color-profile
vmware-tools
slicknav
home-directory
angstrom-linux
hill-climbing
suffix-tree
asp.net5
freelancer.com-api
wyam
embedded-code
0xdbe
ionic
php-ci
operation
generic-programming
cisco-ios
skos
bigbluebutton
jsonpickle
jscript.net
file-copying
rdtsc
typeof
wp-query
dealloc
bundles
mbr
buster.js
orchardcms-1.7
dmoz
sublist
isnullorempty
funscript
gdata-api
libc++
hirefire
subgurim-maps
xmlspy
datareader
radcombobox
preference
scripting-languages
paul-graham
lzh
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