java


Calculate previous day using joda time [duplicate]


This question already has an answer here:
Which Java Date format is this “YYYY-MM-DD 00:00:00+00:00”?
3 answers
I am calculating time based on Hawaii timezone.I have test scenario where my current date is 2017-01-01T10:52:07.656-10:00 (January 1). When I try to get previous date using .minusDays(1) I get date as 2016-12-31T12:52:07.656-08:00 (December 31).
Now for previous date when I try to format in MM/DD/YYYY. I get output as 12/366/2016 instead of 12/31/2016
My code:
DateTime dt4 = new DateTime("2017-01-01T10:52:07.656-10:00");
System.out.println("Given Date:"+ dt4);
DateTimeFormatter fmt = DateTimeFormat.forPattern("MM/DD/YYYY");
System.out.println("Given Date After Date format: "+fmt.print(dt4));
DateTime previousDay = dt4.minusDays(1);
System.out.println("Previous Day: "+ previousDay);
System.out.println("Previous Date After Date format: "+fmt.print(previousDay));
O/p:
Given Date: 2017-01-01T12:52:07.656-08:00
Given date After Date format: 01/01/2017
Previous Day: 2016-12-31T12:52:07.656-08:00
Previous Date After Date format: 12/366/2016
Check this.
You get 366 because 2016 year has 366 days and you chosen the last one.
The Capital D is for Day in year, what i think you want is d lower case for day in month.
If you scroll down you will see some examples that can help you.

Related Links

Work with code from bitbucket: how to make it work locally?
using ArgumentCaptor<List> and hamcrest.hasSize
Add to cart Servlet - how it works
JBoss, IntelliJ IDEA, deploy exploded ear, subdeployment doesn't work
JavaEE WebProject request attribute or JPA entity seems to be cached
how to locate error data in Bulk Insert?
how to publish my jsp project on internet using tomcat,mysql and jdbc driver
Run multiple test using maven command with testing.xml
Proper way to extend ParseObject and have a generic query factory
How can I remove button?
getImage() throws exception on commandline but not in eclipse?
Applet html embedding and I can't seem to locate the .class from my git repo
Permission denied when uploading a video to Facebook in Android
search text for strings in between strings android
detect hashtag and handles in a text under Android
Parallelization of map reduce

Categories

HOME
isabelle
office365api
gis
spring-jdbc
tizen-web-app
gps
volttron
ef-migrations
shared-hosting
scichart
php-openssl
emgucv
opennlp
selectedindexchanged
typo3-6.2.x
opentype
ejabberd-module
kendo-datasource
galsim
.net-4.0
scorm2004
gtrendsr
repo
suricata
space-complexity
withings
code-search-engine
ws-security
sfdc
modelmapper
businessworks
babel-core
fault
chain-builder
rdfs
recursive-datastructures
csound
pearson
flutterwave
imanage
spring-cache
google-cdn
watchconnectivity
angular-strap
visual-c++-2008
gridpane
phishing
fody
underscore.js-templating
thrust
xml-attribute
markojs
master-slave
fadeout
cyclomatic-complexity
purge
sortedlist
rake-task
codeigniter-url
android-nested-fragment
asp.net-web-api-odata
jboss-weld
android-2.2-froyo
concurrent-collections
coverflow
opcache
file-locking
xamlparseexception
android-screen-support
wsdl-2.0
anonymous-methods
chrono
punbb
bigcouch
f#-powerpack
xdomainrequest
cinema-4d
yetanotherforum
appendto
calling-convention
gamma
dentrix
perfect-hash
database-management
premature-optimization

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