How can pure digital String be converted into time?

"20190116100359" converted to 2019-01-16 10:03:59 is this pure String or Int type how to convert to date
download several date types of plug-ins are not ideal. Pure numeric format time is not supported. All returns are false

Apr.26,2022

moment (or luxon)

moment("20190116100359","YYYYMMDDHHmmss").format("YYYY/MM/DD HH:mm:ss")

any format can be converted


moment.js ( https://momentjs.com/)


casually wrote one, because there is no time to verify outside, the general idea should meet your needs

const timeStr = "20190116100359"

const time = timeFormat(timeStr, 'CCCC/CC/CC CC:CC:CC')

function timeFormat(time, format) {
    const timeStr = String(time)
    let index = 0
    let retDate = '' 
    for(let i = 0, l = format.length; i < l; i PP) {
        if (format[i] === 'C') {
            retDate += timeStr[indexPP]
        } else {
            retDate += format[i]
        }
    }

    return retDate
}
Menu