Hallo,

Ik maak met een javascript een datestamp maar ik wil graag weten waar deze datum vandaan komt

ik gebruik dit
datum=new Date();
datum2=datum.getYear()+'-'+datum.getMonth()+'-'+datum.getDay();

maar dat geeft in IE 2005-3-4
en in FF 105-3-4

op de server staat de datum op 07-04-2005


dit gebruik ik voor de tijd en wil hier graag een leading zero hebben maar daar kom ik ook niet uit.

var the_date = new Date();
var the_hour = the_date.getHours();
var the_minute = the_date.getMinutes();
var the_second = the_date.getSeconds();
var the_time = the_hour + ":" + the_minute + ":" + the_second ;

Wie helpt mij hier een goede datum uit te halen?
getday = 1..7
getdate = 1..31

getmonth = 0..11

datum.getYear()+'-'+(datum.getMonth()+1)+'-'+datum.getDate();
function showFilled(Value) {
return (Value > 9) ? "" + Value : "0" + Value;
}

TheTime = new Date();

TimePrint = showFilled(TheTime.getHours()) + ":" + showFilled(TheTime.getMinutes()) + ":" + showFilled(TheTime.getSeconds());

DatePrint = showFilled(TheTime.getDay()) + "-" + showFilled(TheTime.getMonth()) + "-" + TheTime.getYear());
SanThe schreef op 07.04.2005 14:59
function showFilled(Value) {
return (Value > 9) ? "" + Value : "0" + Value;
}

TheTime = new Date();

TimePrint = showFilled(TheTime.getHours()) + ":" + showFilled(TheTime.getMinutes()) + ":" + showFilled(TheTime.getSeconds());

DatePrint = showFilled(TheTime.getDay()) + "-" + showFilled(TheTime.getMonth()) + "-" + TheTime.getYear());

Edit: Als month 0..11 geeft wordt het;

DatePrint = showFilled(TheTime.getDay()) + "-" + showFilled(TheTime.getMonth()+1) + "-" + TheTime.getYear());
Dank je het werkte al maar zoals jij het post is het netter!

Bedankt

Reageren