Wie concat string und Zahl in Typoskript

Ich bin mit der Methode, um Daten

function date() {
    let str = '';

    const currentTime = new Date();
    const year = currentTime.getFullYear();
    const month = currentTime.getMonth();
    const day = currentTime.getDate();

    const hours = currentTime.getHours();
    let minutes = currentTime.getMinutes();
    let seconds = currentTime.getSeconds();
    if (month < 10) {
        //month = '0' + month;
    }
    if (minutes < 10) {
        //minutes = '0' + minutes;
    }
    if (seconds < 10) {
        //seconds = '0' + seconds;
    }
    str += year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds + ' ';

    console.log(str);
}

Und als Ausgabe bekomme ich

2017-6-13 20:36:6 

Ich möchte die gleiche Sache, aber wie

2017-06-13 20:36:06 

Aber wenn ich versuche, auf eine der Zeilen, die ich auskommentiert, zum Beispiel diese eine

month = '0' + month;

Bekomme ich Fehler

Argument of type 'string' is not assignable to parameter of type 'number'.

Wie konnte ich das concat string " und " number?

Verwenden Sie eine andere variable des Typs string?
siehe auch: stackoverflow.com/questions/10073699/...

InformationsquelleAutor Anna F | 2017-07-13

Schreibe einen Kommentar