date + time to timestamp in angular2

青春壹個敷衍的年華 提交于 2019-12-05 17:38:35

You can use plain javascript:

let time = new Date("2016-01-16T16:00:00");
alert(time.getTime());

This will return you a timestamp. Just be aware of timezones.

You can use momentjs to get the desired timestamp.

eg: moment("2016-01-16T16:00:00").format("MM/DD/YYYY HH:mm:ss")

The output will be:

"01/16/2016 16:00:00"

Berlin_Bro

You are on the right path as far as i can see. I suggest you use the Javascript Date https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Date to create a new Date instead of trying to parse the raw output of primeng.

new Date() can be use with a multitude of parameters. If new Date(datestring) is not working out as I would expect, use split to split your output string into variables that u can use to fill

new Date(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);

This might be a little bit of sweat work but it should do the trick.

This is my first answer so please mods be gentle with my formatting.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!