{"id":927,"date":"2018-02-03T17:04:00","date_gmt":"2018-02-03T16:04:00","guid":{"rendered":"http:\/\/blog.via-internet.de\/?p=927"},"modified":"2018-02-03T17:04:00","modified_gmt":"2018-02-03T16:04:00","slug":"ionic-3-working-with-moments-js","status":"publish","type":"post","link":"https:\/\/via-internet.de\/blog\/2018\/02\/03\/ionic-3-working-with-moments-js\/","title":{"rendered":"Ionic | Working with moments.js"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Introduction<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">With <a href=\"http:\/\/momentjs.com\/\">moment.js<\/a>, you can<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Parse, validate, manipulate, and display dates and times in JavaScript.<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">With a npm-Module, you can integrate this functionality into your Ionic App<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Preparation<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">Create your empty app<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ ionic start working-with-moments blank --no-git --no-link<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Install npm Module<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ cd  working-with-moments\n$ npm install moment\n+ moment@2.20.1\nadded 1 package in 3.001s<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Start Editor and serve your app<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ vscode .\n$ ionic serve<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Add moments.js functionality<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Change pages\/home\/home.ts<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Add the moments.js reference to pages\/home\/home.ts<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import { Component } from '@angular\/core'; \nimport { NavController } from 'ionic-angular';\nimport * as moment from 'moment';<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create a var for the current date\/time<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">export class HomePage {\n  public date: any;\n\n  constructor(public navCtrl: NavController) {\n    this.date = moment();\n  }\n}\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Change pages\/home\/home.html<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;ion-content padding>\n  The current date\/time is {{ date }}\n&lt;\/ion-content><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Summary<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">A lot more examples could be found in my <a href=\"https:\/\/github.com\/ionic4-toolbox\/Working-with-moment.js\">repository.<\/a>&nbsp;Just create a starter app with this template and begin to play<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ ionic start app https:\/\/github.com\/ionic4-toolbox\/Working-with-moment.js<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Introduction With moment.js, you can Parse, validate, manipulate, and display dates and times in JavaScript. With a npm-Module, you can integrate this functionality into your Ionic App Preparation Create your empty app Install npm Module Start Editor and serve your app Add moments.js functionality Change pages\/home\/home.ts Add the moments.js reference to pages\/home\/home.ts Create a var for the current date\/time Change pages\/home\/home.html Summary A lot more examples could be found in my repository.&nbsp;Just create a starter app with this template and begin to play<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[98,34],"tags":[],"class_list":["post-927","post","type-post","status-publish","format-standard","hentry","category-ionic","category-ionic-3"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/posts\/927","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/comments?post=927"}],"version-history":[{"count":0,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/posts\/927\/revisions"}],"wp:attachment":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/media?parent=927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/categories?post=927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/tags?post=927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}