• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Calculating last 2 weeks dates.

 
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have to calculate last 2 weeks dates from current time stamp in a particular format of date "dd".How Can i do it in java?
With minimum possible complexity.
This is what I have tried:


How can I proceed further?I have no clue what should I write in getTwoWeeksDates function? How do we calculate previous days in java? I just want only days off last two weeks from current time stamp like this eg: 06,05,04 .......so on
 
Saloon Keeper
Posts: 9734
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used to do this sort of thing with the Date class and GregorianCalendar so I had to poke through the documentation to piece together using the newer LocalDateTime class. If there's a better way, please chime in. LocalDateTime documentation has methods for calculating new dates based on a given day, and getting the day of month.

 
Rancher
Posts: 188
7
Mac OS X IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use Date, use LocalDate.

It has a some useful methods, including minusDays()
 
priyanshi bhardwaj
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:I used to do this sort of thing with the Date class and GregorianCalendar so I had to poke through the documentation to piece together using the newer LocalDateTime class. If there's a better way, please chime in. LocalDateTime documentation has methods for calculating new dates based on a given day, and getting the day of month.



Hi...... Thanks for replying .I am actually developing a module in my  android app using lib: MPAndroidChart . I am creating chart in it. So I have to display days of past two weeks on it's X-Axis . So can you please suggest wt would be the best way to do the same.

 
Carey Brown
Saloon Keeper
Posts: 9734
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adrian Grabowski wrote:Don't use Date, use LocalDate.

It has a some useful methods, including minusDays()


I didn't see a way to convert from millis (e.g. timestamp) to LocalDate, only LocalDateTime. I wasn't sure what to do with the zone though.
 
Sheriff
Posts: 27451
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:I didn't see a way to convert from millis (e.g. timestamp) to LocalDate, only LocalDateTime. I wasn't sure what to do with the zone though.



The original post mentioned "current time stamp" as the starting point. I would reinterpret that as "now" and simply use the static LocalDate method which returns a LocalDate object corresponding to now.
 
A berm makes a great wind break. And we all like to break wind once in a while. Like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic