By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,306 Members | 1,657 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,306 IT Pros & Developers. It's quick & easy.

getting date/time from javascript

P: n/a
I have a page where I need to display the unix time (seconds) upon
page load. I've found many complex examples that auto update, count
live, etc., but I need to just display the time at the time of page
load. I think it has something to do with getTime, showDate, or maybe
loadTime, but I can't quite seem to get the syntax.
Could someone provide the exact syntax and usage within the html to
make this work?

Thanks!

Oct 26 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
wrote on 26 okt 2007 in comp.lang.javascript:
I have a page where I need to display the unix time (seconds) upon
page load. I've found many complex examples that auto update, count
live, etc., but I need to just display the time at the time of page
load. I think it has something to do with getTime, showDate, or maybe
loadTime, but I can't quite seem to get the syntax.
Since "unix time" has different flavours, let me give you this:

var milisecs = +new Date();

gives you the exact number of miliseconds since

var start = new Date(0); // 1 jan 1970 00:00:00:000 UTC

on the local machine.
Could someone provide the exact syntax and usage within the html to
make this work?
So you are not inclined to do some programming yourself?

It seems you need a paid programmer.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 26 '07 #2

P: n/a
In comp.lang.javascript message <Xn********************@194.109.133.242>
, Fri, 26 Oct 2007 17:53:42, Evertjan. <ex**************@interxnl.net>
posted:
>
var milisecs = +new Date();

gives you the exact number of miliseconds since

var start = new Date(0); // 1 jan 1970 00:00:00:000 UTC

on the local machine.
Strictly, not quite exactly.

The number of milliseconds is incremented at an interval which may
average 54.9, 15.625, 10, or other number of milliseconds. Sometimes,
that matters.

And it's the number of milliseconds UT or GMT; UTC has Leap Seconds too.

Using (new Date()/1000)|0 will do for a bit over 30 years

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Oct 26 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.