How to concat string and number in Typescript

Viewed 174794

I am using method to get data

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);
}

And as output I get

2017-6-13 20:36:6 

I would like to get the same thing, but like

2017-06-13 20:36:06 

But if I try one of the lines, that I commented out, for example this one

month = '0' + month;

I get error

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

How could I concat string and number?

6 Answers

You can use it like this. angular environment.ts

const URL = "http://127.0.0.1";
const PORT = "8080";
const API_version = "/api/v1/";

export const environment = {
    production: false,
    BASE_URL: `${URL}:${PORT}${API_version}`
};
Related