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

How to return Calendar object in Custom Date format
Color picker not in activity [closed]
Error creating table using Hibernate Schema Updater
Tray Icon displayed not properly
“out.println” not working in jsp
Delete specific HTML tags in String
How to mock method parameter in Mockito
Table not found error in h2 using hibernate3
Access Report from p:menuitem
Eclipse commands in java code
Add regex matches together
$Class.getResource failed from fat jar packed by maven shade plugin
Java ThreadPool that allocates work by thread name
jackson jersey json : serializing date from java to json
findViewById problems for webview in navigation drawer
For loop how to print to console without leaving on first iteration java

Categories

HOME
sendgrid
testing
date
gitlab
netbeans
zeromq
drivers
comparison
iterator
syntax
sd-card
rsync
amortized-analysis
ezpublish
datastax-java-driver
facebook-messenger-bot
kibana-4
handsontable
qt-creator
try-catch
lombok
libtiff
openrefine
serilog
pythonanywhere
samoa
swingx
kryo
one-hot-encoding
autoconf
abi
sylius
p-value
microsoft-sync-framework
fopen
minitab
maquette
neo4j-spatial
buck
wtx
subdomains
google-cloud-nl
phonegap
force-layout
picasso
suricata
stacked
uft-api
opshub
temporary-files
elasticsearch-plugin
awt
http-redirect
modelmapper
slick-3.0
rainbowtable
atomicity
mu
yii2-extension
pg-dump
nsarray
iso8601
orthogonal
account-kit
mediaelement
nxt
log4c
trash
nsfilemanager
merge-conflict-resolution
essence
rtbkit
lemon
retina
varargs
riak-cs
ibaction
appfabric-cache
apache-commons-fileupload
createprocessasuser
device-orientation
python-green
jsonpickle
dd
knuth
relocation
socketexception
tld
sgen
dml
doskey
uv-mapping
soundtouch
comaddin
lcs
simba
buildr
fireworks
php-parser
external-accessory
locationlistener
sql-server-profiler
h.323
thunderbird-lightning
memory-size
kdbg

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