Home > Mobile >  Javascript date format inside NestJs
Javascript date format inside NestJs

Time:07-19

I have a ScrapeResult mikroOrm entity, I am trying to create a new Date by using this piece of code newScrapeResult.date = new Date() and I am getting 2022-07-17T17:07:24.494Z this output.

I need to convert the above format to yyyy-mm-dd hh mm ss this format. How can I do this? I will save this format to database.

CodePudding user response:

This might help you

function currentTime() {
    let date = new Date()
    let a = date.getFullYear()
    let b = date.getMonth() 1 // JS months are 0 indexed, 0 = January, 11 = December
    let c = date.getDate()

    let d = date.getHours()
    let e = date.getMinutes()
    let f = date.getSeconds()

    return a '-' b '-' c ' ' d ' ' e ' ' f
}
console.log(currentTime())
  • Related