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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:00:31+00:00 2026-05-24T03:00:31+00:00

In my code I need to find all my things that happened today. So

  • 0

In my code I need to find all my things that happened today. So I need to compare against dates from today at 00:00 AM (midnight early this morning) to 12:00 PM (midnight tonight).

I know …

Date today = new Date(); 

… gets me right now. And …

Date beginning = new Date(0);

… gets me zero time on Jan 1, 1970. But what’s an easy way to get zero time today and zero time tomorrow?


UPDATE

I did this, but surely there’s an easier way?

Calendar calStart = new GregorianCalendar();
calStart.setTime(new Date());
calStart.set(Calendar.HOUR_OF_DAY, 0);
calStart.set(Calendar.MINUTE, 0);
calStart.set(Calendar.SECOND, 0);
calStart.set(Calendar.MILLISECOND, 0);
Date midnightYesterday = calStart.getTime();
            
Calendar calEnd = new GregorianCalendar();
calEnd.setTime(new Date());
calEnd.set(Calendar.DAY_OF_YEAR, calEnd.get(Calendar.DAY_OF_YEAR)+1);
calEnd.set(Calendar.HOUR_OF_DAY, 0);
calEnd.set(Calendar.MINUTE, 0);
calEnd.set(Calendar.SECOND, 0);
calEnd.set(Calendar.MILLISECOND, 0);
Date midnightTonight = calEnd.getTime();
  • 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-24T03:00:31+00:00Added an answer on May 24, 2026 at 3:00 am

    java.util.Calendar

    // today    
    Calendar date = new GregorianCalendar();
    // reset hour, minutes, seconds and millis
    date.set(Calendar.HOUR_OF_DAY, 0);
    date.set(Calendar.MINUTE, 0);
    date.set(Calendar.SECOND, 0);
    date.set(Calendar.MILLISECOND, 0);
    
    // next day
    date.add(Calendar.DAY_OF_MONTH, 1);
    

    JDK 8 – java.time.LocalTime and java.time.LocalDate

    LocalTime midnight = LocalTime.MIDNIGHT;
    LocalDate today = LocalDate.now(ZoneId.of("Europe/Berlin"));
    LocalDateTime todayMidnight = LocalDateTime.of(today, midnight);
    LocalDateTime tomorrowMidnight = todayMidnight.plusDays(1);
    

    Joda-Time

    If you’re using a JDK < 8, I recommend Joda Time, because the API is really nice:

    DateTime date = new DateTime().toDateMidnight().toDateTime();
    DateTime tomorrow = date.plusDays(1);
    

    Since version 2.3 of Joda Time DateMidnight is deprecated, so use this:

    DateTime today = new DateTime().withTimeAtStartOfDay();
    DateTime tomorrow = today.plusDays(1).withTimeAtStartOfDay();
    

    Pass a time zone if you don’t want the JVM’s current default time zone.

    DateTimeZone timeZone = DateTimeZone.forID("America/Montreal");
    DateTime today = new DateTime(timeZone).withTimeAtStartOfDay(); // Pass time zone to constructor.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my code I need to compare string letters but my problem is that
I have a code that need to be translated from C to Cpp, and
I need to find out how to format numbers as strings. My code is
I found all the code I need to make SHBrowseForFolder work in my application.
I have existing java code and need to create Design Document based on that.
Am I doing something wrong if I need code like this in a Controller?
As a scientist not a software engineer I find that my code is generally
Both my Rails model and controller code need to write files to the file
I need code in Perl for requesting and parsing ATOM and RSS feeds. Is
i have the following code ..i need to loop through end of the file

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.