| 1. |
How To Convert Date In Aurelia? |
|
Answer» Convert Date : When we want to convert default date value to some specific format, we can use momentJS library. This is SMALL library used for manipulating dates. C:UsersusernameDesktopaureliaApp>jspm install MOMENT Let's create new file converters.js. We will use this file to ADD converter specific code. Use the following command or create the file manually. C:UsersusernameDesktopaureliaApp>touch converters.js converter.js : Inside this file we will import moment library and set DateFormatValueConverter to return only MONTH, day and year values without additional data. Important thing to note is that Aurelia can recognize any class that ends with ValueConverter. This is why our class name is DateFormatValueConverter. This class will be registered as dateFormat and we can later use it inside view. converters.js { { } In app.js we will just use current date. This will be our view-model. export class App { { You already saw require in custom-elements CHAPTER. The pipe symbol | is used to apply the converter. We are only using dateFormat since this is how Aurelia is registering DateFormatValueConverter. app.html Convert Date : When we want to convert default date value to some specific format, we can use momentJS library. This is small library used for manipulating dates. C:UsersusernameDesktopaureliaApp>jspm install moment Let's create new file converters.js. We will use this file to add converter specific code. Use the following command or create the file manually. C:UsersusernameDesktopaureliaApp>touch converters.js converter.js : Inside this file we will import moment library and set DateFormatValueConverter to return only month, day and year values without additional data. Important thing to note is that Aurelia can recognize any class that ends with ValueConverter. This is why our class name is DateFormatValueConverter. This class will be registered as dateFormat and we can later use it inside view. converters.js { { } In app.js we will just use current date. This will be our view-model. export class App { { You already saw require in custom-elements chapter. The pipe symbol | is used to apply the converter. We are only using dateFormat since this is how Aurelia is registering DateFormatValueConverter. app.html |
|