简体   繁体   English

如何将日期转换为角度为2的时间戳字符串

[英]How to Convert Date to a Timestamp string angular 2

How do I convert a Date to a timestamp string? 如何将日期转换为时间戳字符串?

my variable is: 我的变量是:

d: Date = new Date();

how do I get a timestamp of that variable? 如何获得该变量的时间戳?

I'm using Angular2. 我正在使用Angular2。 Pleas help 求助

This more a javascript question than angular/typescript, but you can get a timestamp using 与angular / typescript相比,这更是一个JavaScript问题,但是您可以使用获得时间戳

Date.now(); // return timestamp

You can read more here: How do you get a timestamp in JavaScript? 您可以在此处了解更多信息: 如何获取JavaScript时间戳?

您可以使用Moment.js或Angular管道:

{{valueDate | date: 'dd/MM/yyyy'}}

You can try 你可以试试

d: string = new Date().toLocaleString();

Or toISOString() toISOString()

But you can find best solutions here 但是您可以在这里找到最佳解决方案

https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM