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
  • 18,936
  • 23
  • 91
  • 177
Sergio Mendez
  • 1,311
  • 8
  • 33
  • 56
  • 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
  • 18,936
  • 23
  • 91
  • 177
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,988
  • 9
  • 25
  • 38
TheCoderGuy
  • 771
  • 6
  • 24
  • 51