0

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. Pleas help

Syntactic Fructose
  • 17,149
  • 19
  • 87
  • 170
Sergio Mendez
  • 1,031
  • 7
  • 28
  • 48
  • Possible duplicate of [How do you get a timestamp in JavaScript?](https://stackoverflow.com/questions/221294/how-do-you-get-a-timestamp-in-javascript) – Syntactic Fructose Apr 03 '18 at 23:12
  • What format should the timestamp be in? Possible duplicate of [*Format Date time in AngularJS*](https://stackoverflow.com/questions/12920892/format-date-time-in-angularjs) – RobG Apr 03 '18 at 23:21

3 Answers3

1

This more a javascript question than angular/typescript, but you can get a timestamp using

Date.now(); // return timestamp

You can read more here: How do you get a timestamp in JavaScript?

Syntactic Fructose
  • 17,149
  • 19
  • 87
  • 170
0

You can use Moment.js or an Angular pipe:

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

You can try

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

Or toISOString()

But you can find best solutions here

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

rollstuhlfahrer
  • 3,888
  • 9
  • 23
  • 37
Abedin.Zhuniqi
  • 855
  • 5
  • 20
  • 41