O'Reilly logo

Hands-On Full Stack Web Development with Aurelia by Erikson Haziz Murrugarra Sifuentes, Diego Jose Arguelles Rojas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The problem – Data is not exposed as we need

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required