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

The Archive Base Latest Questions

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

I want to know whether the Time values of a Calendar object equal the

  • 0

I want to know whether the Time values of a Calendar object equal the value of a java.sql.Time object.

E.g

Calendar c; //c.getTime().toString() == "Sat Jan 07 09:00:00 GMT 2012"
Time t;     //d.toString() == "09:00:00";

I tried

t.equals(c.getTime())

But because the Calendar has Date information the expression is false.

What would be the best way the compare the two?

Edit:
The Time object is retrieve though Hibernate and come with no date information.

The Calendar object is create by

Calendar c= Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, 9);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
  • 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-28T03:12:32+00:00Added an answer on May 28, 2026 at 3:12 am

    The way you use is perfectly fine. The goal is unclear, though. Why do you want c to be equal to d?

    Additionally, there’s no way to have d.toString() == "09:00:00" — Date always have, well, the date included.

    What’s more important, though, is that Date has no timezone information (well, it used to have, but you’re discouraged to touch this part of Date), so you cannot tell 09:00 UTC from 10:00 BST—that is, unless you specify the timezone. You can get the timezone from Calendar c, and it sort of explains what you need to do:

    1. Create a Calendar from your date
    2. Copy timezone from the calendar you already use
    3. Compare the Calendar fields which are of interest for you. I suppose that will be hour, minute, second, and, perhaps, millisecond.

    Update: now that you’ve mentioned it’s actually java.sql.Time, I’m worried. The problem is,

    • SQL servers usually store time as a structure containing hours, minutes, seconds, etc. That is, there’s an implied timezone (the SQL Server timezone)
    • java.sql.Time stores time as milliseconds since “zero epoch” value of January 1, 1970. The date part is usually stripped to January 1, 1970 — but this class does not contain timezone information. (Well, again, it sort of does, but it’s deprecated.)
    • Calendar has an explicitly set timezone

    What it means in practice is, that the time from the server gets converted into milliseconds using system default timezone, then you read this value and compare it with a Calendar with its own timezone.

    If it sounds confusing and fragile, that’s because it is. So basically you have three timezones:

    1. SQL Server TZ
    2. JVM’s default TZ
    3. Calendar’s TZ

    All three must be the same so that any comparison would make any sense.

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

Sidebar

Related Questions

Using Python, I want to know whether Java is installed.
I want to know whether the current time is present between the start time
I want to know whether creating a new thread in Java triggers a cache
I want to know whether it is possible to save as an array list
I want to know whether it is possible to have multiple stores under 1
I want to know whether 301 redirect always preserve referrer. I make a page
I want to know whether it is possible to commit to a previous version.
I want to know whether it is possible to transform Relax NG XML with
I want to know whether the PHP serialize function is 100% secure, also if
I want to know whether Metro Applications developed using Visual Studio 11 Developer Preview

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.