1

can someoe explain to me this example, please: http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_gettime

function myFunction()
{
var d = new Date();
var x = document.getElementById("demo");
x.innerHTML=d.getTime();
}

So there is variable that holds current date, putting some data into element with "demo" id. But where on earth is something that tells me anything about:January 1, 1970? Is it something like mysterious date - known to everybody?

The second question is: why my fiddle doesn't work?:( http://jsfiddle.net/jwUzM/3/

Thanks!

Mag
  • 715
  • 2
  • 6
  • 15
  • You never defined currentdate in your fiddle – francisco.preller Oct 08 '13 at 05:54
  • 2
    Your fiddle doesn't work because you're asking for `currentdate`, which doesn't exist anywhere. – Evan Trimboli Oct 08 '13 at 05:54
  • Don't use W3Schools. For language questions, [ECMA-262](http://www.ecma-international.org/ecma-262/5.1/) is the best reference, e.g. [time values](http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1). For examples and other information, the [MDN JavaScript reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference) is good, and the [User Guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide) is very helpful too. – RobG Oct 08 '13 at 06:15

5 Answers5

1

Please refer this links for January 1 ,1970 http://en.wikipedia.org/wiki/Unix_time

Your fiddle contains an undefined variable 'currentdate'. That's why it's not working

karthick
  • 11,998
  • 6
  • 56
  • 88
1

First Question:

Epoch time , is basically a representation of the number of seconds since 1 jan 1970 as others have pointed out .

Read more about it here ..

Second Question:

You haven't declared currentdate but used it to insert value to the innerhtml . the line declares currentdate as a variable of type date.

var currentdate= new Date();

add this to your script to solve the issue.

Also you have -> var date = currentdate.getDate();, however date is not being used , its presence is no problem but remove it if you aren't gonna use it.

Community
  • 1
  • 1
Arun
  • 584
  • 1
  • 6
  • 19
1

In your Fiddle the currentdate variable is invalid I have updated that. Check it out..

var diag = "AM";
var currentdate = new Date();
var date = currentdate.getDate();
var timer = document.getElementById("timer");

timer.innerHTML= currentdate.getDate();

http://jsfiddle.net/jwUzM/10/

Srinath Thota
  • 1,208
  • 12
  • 17
0

January 1, 1970 is a start of Unix Epoch.

See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Parameters

Eugene Naydenov
  • 7,165
  • 2
  • 25
  • 43
0

About the first question: January first, 1970 is the start of Unix Time. Why it's January first, 1970 and not March 4-th, 1977, you can find in this article:

At the time we didn't have tapes and we had a couple of file-systems running and we kept changing the origin of time," he said. "So finally we said, 'Let's pick one thing that's not going to overflow for a while.' 1970 seemed to be as good as any.

aga
  • 27,954
  • 13
  • 86
  • 121