日期+时间戳记的时间角度2 [英] date + time to timestamp in angular2

查看:91
本文介绍了日期+时间戳记的时间角度2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习angular2 +,我想制作一个类似于GoogleCalendar的调度程序应用程序. 经过大量研究,我决定使用PrimeNG.日历的输出格式为

Am trying to learn angular2+ and i want to make a GoogleCalendar's like scheduler app. After many research, i decided to use PrimeNG. The output format of the calendar is

2016-01-16T16:00:00

这看起来很棒而且完整.但是我想与之交互的api使用timeStamp ...

that's seems great and complete. But the api i want to interract with uses timeStamp...

我试图创建一个解析我的日期格式的Javascript函数:

I tried to make a Javascript function who's parsing my date format :

   function toTimestamp(strDate){
   var datum = Date.parse(strDate);
   return datum/1000;
}
alert(toTimestamp('02/13/2009 23:31:30'));

但是我的问题是我无法使用PrimeNG的格式...

But my problem is that i can't use the format of PrimeNG...

有人知道我如何才能与需要转换为时间戳的格式进行交互吗?

Did anyone know how can i interact corectly with the format i need to convert to a timestamp?

否则,没有人知道如何使用angular2 +将此日期格式(2016-01-16T16:00:00)转换为时间戳吗? 非常感谢 !!

else did anyone know how can i get this date format ( 2016-01-16T16:00:00 ) to a timestamp using angular2+ ? Thanks very much !!

推荐答案

您可以使用普通的javascript:

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.

这篇关于日期+时间戳记的时间角度2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆