-6

I have a little script that lets me show the TIME (Live) in a div…

See it here in the JS Fiddle:

http://jsfiddle.net/jy0mLmkw/

But I would like to have only the DATE shown, like 17/02/2015 …

Can I just change it to:

Heute = new Date();
day = Heute.getDay();
month = Heute.getMoth();
year = Heute.getYear();

… Is getDay(); et cetera valid JS syntax?

Thank you for any help!

Cyrill
  • 833
  • 2
  • 6
  • 16
  • 1
    This tells you everything you need to know https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date – Joe Feb 17 '15 at 15:28
  • Sure it will work. You can then use those variables to display the date as you wish. Have a look here to see all methods you can use with a Date object (edited to change reference from W3Schools to MDN): see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date – Danilo Feb 17 '15 at 15:29
  • 2
    @Danilo please don't use W3Schools as a reference: http://w3fools.com. If you want a reference, use MDN. – Rory McCrossan Feb 17 '15 at 15:30
  • Many downvotes I think because you suggest something, but you don't even try it... And there are probably LOTS of similar questions already in SO – Cyril Duchon-Doris Feb 17 '15 at 15:30
  • Downvotes because it's easy to find in the documentation. – Joe Feb 17 '15 at 15:35
  • I am a total rookie in JS … And I tried it myself … But the date i got was always wrong, so I thought of asking … But thank you for any helping comment… Thank you Joe, the documentation helps… – Cyrill Feb 17 '15 at 16:50

1 Answers1

1

You can get the date with javascript like so:

var date = new Date();
var d  = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;

Check a working example here

There is also a similar answer: How do I get the current date in JavaScript?

Community
  • 1
  • 1
cch
  • 3,336
  • 8
  • 33
  • 61