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

2

3 Answers 3

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?

Sign up to request clarification or add additional context in comments.

Comments

1

You can use Moment.js or an Angular pipe:

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.