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

  • Home
  • SEARCH
  • 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 81181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:25:11+00:00 2026-05-10T21:25:11+00:00

In Java, given a timestamp, how to reset the time part alone to 00:00:00

  • 0

In Java, given a timestamp, how to reset the time part alone to 00:00:00 so that the timestamp represents the midnight of that particular day ?

In T-SQL, this query will do to achieve the same, but I don’t know how to do this in Java.

SELECT CAST( FLOOR( CAST(GETDATE() AS FLOAT ) ) AS DATETIME) AS 'DateTimeAtMidnight';

  • 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. 2026-05-10T21:25:11+00:00Added an answer on May 10, 2026 at 9:25 pm

    You can go Date->Calendar->set->Date:

    Date date = new Date();                      // timestamp now Calendar cal = Calendar.getInstance();       // get calendar instance cal.setTime(date);                           // set cal to date cal.set(Calendar.HOUR_OF_DAY, 0);            // set hour to midnight cal.set(Calendar.MINUTE, 0);                 // set minute in hour cal.set(Calendar.SECOND, 0);                 // set second in minute cal.set(Calendar.MILLISECOND, 0);            // set millis in second Date zeroedDate = cal.getTime();             // actually computes the new Date 

    I love Java dates.

    Note that if you’re using actual java.sql.Timestamps, they have an extra nanos field. Calendar of course, knows nothing of nanos so will blindly ignore it and effectively drop it when creating the zeroedDate at the end, which you could then use to create a new Timetamp object.

    I should also note that Calendar is not thread-safe, so don’t go thinking you can make that a static single cal instance called from multiple threads to avoid creating new Calendar instances.

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

Sidebar

Ask A Question

Stats

  • Questions 67k
  • Answers 67k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You can't do it in the XAML but you can… May 11, 2026 at 11:46 am
  • added an answer If the configuration you've got works now, why mess with… May 11, 2026 at 11:46 am
  • added an answer Well, go to the *scratch* buffer and use set-frame-width. (set-frame-width… May 11, 2026 at 11:46 am

Related Questions

In Java, given a timestamp, how to reset the time part alone to 00:00:00
Given a java.util.Date object how do I go about finding what Quarter it's in?
Given a large API (an in particular, the Java or J2EE standard libraries), is
Upcasting is allowed in Java, however downcasting gives a compile error. The compile error
In Java you can give the number zero as a single parameter for the
When I give Java and C large floats and doubles (in the billion range),
In Java 5 and above you have the foreach loop, which works magically on
In Java, there is no such thing as an unsigned byte. Working with some
In Java, what would the best way be to have a constantly listening port
In Java, I have a String and I want to encode it as a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.