Creating a timestamp in Typescript | Quickies in Angular

Jorge Guerra Pires, PhD
IdeaCoding Lab
Published in
2 min readJul 8, 2022

--

Photo by Towfiqu barbhuiya on Unsplash

Frequently, I found myself needing a time (current date), a simple solution. Interesting enough, there is no simple solution in JavaScript. Here goes my simple solution.

Install the dependence

This is a normal NPM package, as any package, just use NPM.

npm i ideacodinglab

You can check your package.json file, it should be there! 😎🤗

Using the date at a Typescript file

Using the date at a HTML file

The HTML is bound to the TS file, thus, you need to make sure it starts before the HTML (e.g., put the method calling at the ngOnInit method, or constructor).

What you will see at the HTML

Sandbox

Photo by Alexander Dummer on Unsplash

You can find the live app here.

Comments

The output is a string, if you need a date format, it may be a problem. I have passed using an interface in Typescript set as date, and it worked just fine.

--

--

Jorge Guerra Pires, PhD
IdeaCoding Lab

Independent Researcher and writer at Amazon | “I want thinkers, not followers!” | More: https://linktr.ee/jorgeguerrapiresphd