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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:14:20+00:00 2026-05-23T14:14:20+00:00

Hello all javascript guru, I’ve came across this javascript code that struggled me abit

  • 0

Hello all javascript guru,

I’ve came across this javascript code that struggled me abit to understand why it didn’t work as expected. So thought i post it here seeking for your help.

Basically the code is to convert a Date to milliseconds format and that milliseconds value then be converted back to Date object again but when comparing, they are NOT equal?

var currentTime = new Date();
var currentTimeInMill = Date.parse(currentTime);
var currentTime2 = new Date(currentTimeInMill);

// debug in firefox
console.log(currentTime);
// Date {Thu Jul 07 2011 09:56:19 GMT+1000 (AUS Eastern Standard Time)}

console.log(currentTime2);
// Date {Thu Jul 07 2011 09:56:19 GMT+1000 (AUS Eastern Standard Time)}

console.log(currentTime == currentTime2);
// false

My question is why that 2 values currentTime and currentTime2 are not equal even their values “look” the same in Firefox console.log?

  • 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-23T14:14:21+00:00Added an answer on May 23, 2026 at 2:14 pm

    Because, as minitech points out, milliseconds are stripped from the Date object’s toString method, in order to be absolutely sure that the numeric value of currentTime equals that of currentTime2, you’ll need to set the milliseconds of currentTime2:

    currentTime2.setMilliseconds(currentTime % 1000);
    

    Then, as cwolves points out, you can compare each Date‘s getTime output. So when complete, it would look something like this:

    var currentTime = new Date();
    var currentTimeInMill = Date.parse(currentTime);
    var currentTime2 = new Date(currentTimeInMill);
    currentTime2.setMilliseconds(currentTime % 1000);
    
    // debug in firefox
    console.log(currentTime);
    // Date {Thu Jul 07 2011 09:56:19 GMT+1000 (AUS Eastern Standard Time)}
    
    console.log(currentTime2);
    // Date {Thu Jul 07 2011 09:56:19 GMT+1000 (AUS Eastern Standard Time)}
    
    console.log(currentTime.getTime() == currentTime2.getTime());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem Hello all! I have this code which takes my jpg image loops through
Hello JavaScript guru's. I have a simple JS question on how to replace all
My javascript looks like the following. I don't understand why these methods are all
I have this simple hello world version of a google map api javascript v3
Link to code Hello all, I have a circle menu (above link) where I
Hello all I'm getting this very strange error: java.lang.NoSuchMethodError: org.hibernate.SessionFactory.getCurrentSession()Lor g/hibernate/classic/Session; at org.cometd.hibernate.util.HibernateUtil.getSessionFactory(HibernateUt il.java:29)
Hello I have some javascript code, a script included inside my page. I want
Usless Background Info Hello, all. This is my first post here, but I often
Suppose that I have a string $var : //php code $var = hello,world,test; $exp
I am working on a PHP app that requires eight javascript files (hello web2.0).

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.