Server Timestamp

5,145 views
Skip to first unread message

Tolgay Toklar

unread,
Apr 5, 2013, 11:56:49 AM4/5/13
to nod...@googlegroups.com
Hi

How can I get server timestamp in nodejs ? (Like a php time() function)

Arnout Kazemier

unread,
Apr 5, 2013, 11:59:20 AM4/5/13
to nod...@googlegroups.com

On Friday 5 April 2013 at 17:56, Tolgay Toklar wrote:

Hi

How can I get server timestamp in nodejs ? (Like a php time() function)

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Herman Junge

unread,
Apr 5, 2013, 12:02:11 PM4/5/13
to nod...@googlegroups.com
console.log(new Date()).getTime();

On 4/5/13 12:56 PM, Tolgay Toklar wrote:
> Hi
>
> How can I get server timestamp in nodejs ? (Like a php time() function)

Trygve Lie

unread,
Apr 5, 2013, 12:02:52 PM4/5/13
to nod...@googlegroups.com
var timestamp = +new Date();

Trygve

Dan Milon

unread,
Apr 5, 2013, 12:12:15 PM4/5/13
to nod...@googlegroups.com
If all you need is time elapsed since epoch, you dont wanna do that.
Nor `+new Date()`. They are way more expensive than a plain `Date.now()`.

https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/now

Tolgay Toklar

unread,
Apr 5, 2013, 2:56:55 PM4/5/13
to nod...@googlegroups.com
Thanks for answers.

But there is a problem: Php time() function returns 10 digit number.Javascript Date.now() function returns 13 digit number.How can I resolve this problem ? I can't do process on numbers.

5 Nisan 2013 Cuma 18:56:49 UTC+3 tarihinde Tolgay Toklar yazdı:

Dan Milon

unread,
Apr 5, 2013, 3:02:44 PM4/5/13
to nod...@googlegroups.com
Read the documentation.

Date.now(), Date#getTime(), etc return the number of milliseconds
since epoch. Whereas php's time() returns seconds. Hence the 3 digit
difference.

Math.round(Date.now() / 1000)

That converts from ms to s.

Arnout Kazemier

unread,
Apr 5, 2013, 3:14:14 PM4/5/13
to nod...@googlegroups.com
nonono, you heard him he can't process on the numbers.

On Friday, April 5, 2013 at 9:02 PM, Dan Milon wrote:

Math.round(Date.now() / 1000)

Tolgay Toklar

unread,
Apr 5, 2013, 3:20:39 PM4/5/13
to nod...@googlegroups.com
Thank you so much to everybody :)

Math.round(Date.now() / 1000)

This code resolved my problem.


5 Nisan 2013 Cuma 18:56:49 UTC+3 tarihinde Tolgay Toklar yazdı:
Hi
Reply all
Reply to author
Forward
0 new messages