1

I use this new Date.getTime() to get current timestamp in jquery. It gave me value 1380796448330

But when I checked with PHP time() function it gave me :1380796567

Why is there a difference in length of both values?

7
  • 3
    What about looking at the documentation? Commented Oct 3, 2013 at 10:56
  • and here come downvoters..thanks.. Commented Oct 3, 2013 at 10:58
  • Considering that the tooltip for the downvote button begins with "This question does not show any research effort", I don't believe you have grounds to complain. Not to mention complain about earning less rep which the 5/1 weight ratio ensures. Commented Oct 3, 2013 at 11:00
  • I am not complaining..but there is an another line in tooltip which says "not useful", i guess its not that useless ;) no grudges though :) and rep is not the thing i use SO for :) Commented Oct 3, 2013 at 11:02
  • Actually this is a common question that people are tend to ask frequently so I assume it could be useful for others as well if they google and find it here. Commented Oct 3, 2013 at 11:04

2 Answers 2

8

The JavaScript Date.getTime method returns the time since start of Unix Epoch in milliseconds and PHP time() function returns it in seconds.

So if you want to use the timestamp from client-side in PHP you should divide it by thousand.
And vice versa if you want to use the timestamp retrieved in PHP at the client side (e.g. to pass it into the Date constructor) you should multiply it to thousand.

Sign up to request clarification or add additional context in comments.

1 Comment

Also, I like to add JQuery/Javascript use timestamp based on the Browser, where as PHP use Timestamp of Server, so if server is different from client machine than their time might be different.
1

Hi difference is mentioned here take look (Counted Timestamp blog) and will help u ... http://cw.tactileint.com/++Dates_and_Times/JavaScript,PHP

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.