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 8510689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:46:25+00:00 2026-06-11T03:46:25+00:00

I have some documents and its created time is in milliseconds. I need to

  • 0

I have some documents and its created time is in milliseconds.
I need to separate them as Today, Yesterday, Last 7 Days, Last 30 Days, More than 30 Days.

I used the following code:convertSimpleDayFormat(1347022979786);

public static String convertSimpleDayFormat(Long val) {


            long displayTime = System.currentTimeMillis() - val;
            displayTime = displayTime/86400000;
            String displayTimeVal = "";
            if(displayTime <1)
            {
                    displayTimeVal = "today";  
            }
            else if(displayTime<2)
            {
                    displayTimeVal = "yesterday";
            } 
            else if(displayTime<7)
            {
                    displayTimeVal = "last7days";
            } 
            else if(displayTime<30)
            {
                    displayTimeVal = "last30days";
            }
            else
            {
                    displayTimeVal = "morethan30days";
            }
            return displayTimeVal;
    }

I am subtracting the current time and passing the milliseconds and converting to one day.

But the issue I’m facing is, I couldn’t calculate the exact time for the date in milliseconds.

I want to calculate for Today as: From Midnight 00:00 to Midnight 24:00. (Exactly for 24 hours.)

Similarly I want to exactly convert the Milliseconds into Today, Yesterday, Last 7 days, Last 30 Days and More than 30 Days.

  • 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-06-11T03:46:27+00:00Added an answer on June 11, 2026 at 3:46 am
    private static Calendar clearTimes(Calendar c) {
        c.set(Calendar.HOUR_OF_DAY,0);
        c.set(Calendar.MINUTE,0);
        c.set(Calendar.SECOND,0);
        c.set(Calendar.MILLISECOND,0);
        return c;
    }
    
    public static String convertSimpleDayFormat(long val) {
        Calendar today=Calendar.getInstance();
        today=clearTimes(today);
    
        Calendar yesterday=Calendar.getInstance();
        yesterday.add(Calendar.DAY_OF_YEAR,-1);
        yesterday=clearTimes(yesterday);
    
        Calendar last7days=Calendar.getInstance();
        last7days.add(Calendar.DAY_OF_YEAR,-7);
        last7days=clearTimes(last7days);
    
        Calendar last30days=Calendar.getInstance();
        last30days.add(Calendar.DAY_OF_YEAR,-30);
        last30days=clearTimes(last30days);
    
    
        if(val >today.getTimeInMillis())
        {
                return "today";  
        }
        else if(val>yesterday.getTimeInMillis())
        {
            return "yesterday";
        } 
        else if(val>last7days.getTimeInMillis())
        {
            return "last7days";
        } 
        else if(val>last30days.getTimeInMillis())
        {
            return "last30days";
        }
        else
        {
            return "morethan30days";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some xml documents I need to run queries on. I've created some
I have some pdf documents and I need to find a way to automate
I have created some documents and managed to make some simple queries but I
I have created a repeat control that list some documents. I would like to
I have to manipulate some Excel documents with C#. It's a batch process with
I have some documents in couchdb that have fields that are arrays of id's
The limitation of one document in MongoDB is 4Mo. I have some documents really
I have some table DOCUMENTS that have a column TYPE_ID and a table named
I have some python code using shutil.copyfile: import os import shutil src='C:\Documents and Settings\user\Desktop\FilesPy'
I have a strange problem with some documents on my webpage. My data is

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.