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.
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