Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7544601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:42:50+00:00 2026-05-30T08:42:50+00:00

If I have a vector containing a number of unsorted files, how can I

  • 0

If I have a vector containing a number of unsorted files, how can I categorize them by their last modified date?

what I need to do is to place the files into 3 other vectors, with the last modified date of “Today”, “Yesterday”, and “This Week”.

Vector<File> files;  //This vector contains all the files that need to be categorized
Vector<File> todayFiles;  //Empty
Vector<File> yesterdayFiles;  //Empty
Vector<File> weekFiles;  //Empty

I know I can use file.lastModified() to get the date, but it returns the date in milliseconds formatted as a long int, so I am not sure if there is an easier way to compare and group the dates without doing some intricate arithmetic work.

I am new to Java, so I have no idea how to approach this question, any help would be appreciated.

UPDATE

I was able to get the code to work somehow, but it is still not working properly. This is what I have:

private Calendar cal;
private long todayTime;

this.cal = Calendar.getInstance();
this.cal.set(Calendar.HOUR_OF_DAY, 0);
this.cal.set(Calendar.HOUR, 0);
this.cal.set(Calendar.MINUTE, 0);
this.cal.set(Calendar.SECOND, 0);
this.cal.set(Calendar.MILLISECOND, 0);
this.todayTime = cal.getTimeInMillis();

Now when I try to add them into the vector that I created, it is only grabbing files that have been modified in the PM of today’s date:

for(int i = 0; i < this.files.size(); i++) {
    if(this.files.get(i).lastModified() >= this.todayTime) {
        this.today.add(this.files.get(i));  
    }
}

Is there anything that I am doing wrong? Thank you for all the great responses by the way!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:42:51+00:00Added an answer on May 30, 2026 at 8:42 am

    You can use the Calendar class to get timestamps for the required dates such as today and yesterday. For example, to get today’s (midnight) timestamp:

    Calendar cal = Calendar.getInstance();
    // cal initially contains current time
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    
    long todayTimestamp = cal.getTimeInMillis();
    

    Then you can compare this timestamp with file.lastModified() and put the file into the corresponding vector.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a vector containing n elements. I need to choose a subset of
I have a vector containing large number of elements. Now I want to write
I have a number of vector containers of varying size each containing doubles. I
I have a very large std::vector of std::vectors containing a fixed number of unsigned
I have a vector containing the values 0, 1, 2 and 3. What I
I have some data structures: all_unordered_m is a big vector containing all the strings
in clojure i have vector [myfn1 myfn2 myfn3] how can i call functions named
I have created a vector containing zeros and 1's using the following command in
I have two variables, the first is 1D flow vector containing 230 data and
We have an Excel file with a worksheet containing people records. 1. Phone Number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.