My input is
var dt = "06/01/2018"
var time = "06:25:00"
i want output to be in string like this "2018-06-01T00:55:00.000Z"
.
I did var result = new Date(dt+time); //output is object here
var result = new Date(dt+time); //output is object here
I want to convert that object to string. Can any one tell me how to do that.
There is no need to use a Date
object if the dt
and time
formats are known in advance. Here is how you can do it
const dt = '06/01/2018'; const [mm,dd,yyyy] = dt.split('/') const time = '06:25:00'; const date = `${yyyy}-${mm}-${dd}T${time}.000Z`; console.log(date);
const dt = '06/01/2018'; var time = "06:25:00"; console.log(new Date(`${dt} ${time}`).toJSON())
var dt = "06/01/2018"; var time = "06:25:00"; var date_test = new Date((dt + ' ' + time)).toString(); console.log(date_test);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.