One of the common problems we could have is the date formatting. In other code languages such as Java, you have a utility class like SimpleDateFormat, which converts the Date() object to a more friendly human reading format. In JavaScript, we have some libraries to do that job, but they are not so simple to call. Let's see an example.
You get the current date in your ViewModel component; then, you pass that value to the View layer:
export class Example { constructor() { this.changeDate(); setInterval(() => this.changeDate(), 3000); //<<-- This method will be executed each 3 seconds } changeDate() { this.currentDate = new Date(); //<<-- Get the current date } }
In our View file, we map the currentDate ...