Delete records from more than 1 year ago

前端 未结 4 654
说谎
说谎 2021-01-18 02:26

I\'m saving twitter tweets in my database with spring JPA Repositories. The date of the tweet is saved as Datetime in the MySQL db. Now I want to delete all tweets that are

4条回答
  •  执念已碎
    2021-01-18 02:41

    If you want the current time you could use

    System.getCurrentTimeMillis()
    

    Take the time from the old date and subtract it from the current one then you just have to compare it with the duration of one year. Maybe you should add something for leap-years.

提交回复
热议问题