date-pipe

Angular 4 Date Pipe converting wrongly

六月ゝ 毕业季﹏ 提交于 2019-11-27 03:17:13
问题 I have rest service which returns a collection of objects and one of the field of the item is a date string (ISO-8601 format ) and the date value as follows "createdDate" : "2017-02-21T12:56:50.907", In the angular4 UI I put DatePipe to format the above date {{resultItem.createdDate| date:'short'}} and I am getting wrong conversion as follows 2/21/2017, 7:56 AM instead of 2/21/2017, 0:56 AM 回答1: You may need to create a UTC date from your date with timezone... I assume you are in the pacific

How to use angular2 built-in date pipe in services and directives script files [duplicate]

柔情痞子 提交于 2019-11-27 03:03:12
问题 This question already has an answer here: How to use a pipe in a component in Angular 2? 3 answers I need to use angular2's date pipe in services and directives script files(not only in HTML). Does anyone have ideas? Can't upload code cos some policy restrictions, sorry about that. 回答1: Since CommonModule does not export it as a provider you'll have to do it yourself. This is not very complicated. 1) Import DatePipe: import { DatePipe } from '@angular/common'; 2) Include DatePipe in your

How can I deal with the timezone issue with the Angular 4 date pipe?

a 夏天 提交于 2019-11-26 22:47:49
问题 I have a date value in each of my objects that I can Print like this: <td> {{competition.compStart }}</td> And here is how it looks: 1931-05-31T00:00:00.000+0000 In order to change the format to make it more readable I'm using the Angular date pipe: <td> {{competition.compStart | date : "dd/MM/yyyy"}}</td> With this result: 30/05/1931 As you can see, It is displaying the previous day (May 30 instead of May 31). As far as I understand, the problem is related to the timezone, since I'm in

Format date as dd/MM/yyyy using pipes

痞子三分冷 提交于 2019-11-26 14:10:18
I'm using the date pipe to format my date, but I just can't get the exact format I want without a workaround. Am I understanding pipes wrongly or is just not possible? //our root app component import {Component} from 'angular2/core' @Component({ selector: 'my-app', providers: [], template: ` <div> <h2>Hello {{name}}</h2> <h3>{{date | date: 'ddMMyyyy'}}, should be {{date | date: 'dd'}}/{{date | date:'MM'}}/{{date | date: 'yyyy'}}</h3> </div> `, directives: [] }) export class App { constructor() { this.name = 'Angular2' this.date = new Date(); } } plnkr view Pipe date format bug fixed in Angular

Format date as dd/MM/yyyy using pipes

好久不见. 提交于 2019-11-26 03:06:04
问题 I\'m using the date pipe to format my date, but I just can\'t get the exact format I want without a workaround. Am I understanding pipes wrongly or is just not possible? //our root app component import {Component} from \'angular2/core\' @Component({ selector: \'my-app\', providers: [], template: ` <div> <h2>Hello {{name}}</h2> <h3>{{date | date: \'ddMMyyyy\'}}, should be {{date | date: \'dd\'}}/{{date | date:\'MM\'}}/{{date | date: \'yyyy\'}}</h3> </div> `, directives: [] }) export class App

How to set locale in DatePipe in Angular 2?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 01:57:49
问题 I want to display Date using European format dd/mm/yyyy but using DatePipe shortDate format it only display using US date style mm/dd/yyyy . I\'m assuming thats the default locale is en_US. Maybe I am missing in the docs but how can I change the default locale settings in an Angular2 app? Or maybe is there some way to pass a custom format to DatePipe ? 回答1: As of Angular2 RC6, you can set default locale in your app module, by adding a provider: @NgModule({ providers: [ { provide: LOCALE_ID,