date-pipe

How to get date and time in Angular 4 using DatePipe

ぐ巨炮叔叔 提交于 2020-01-12 07:40:13
问题 I am working in an angular 4 application ,Here I need to get the current Date and Time Using angular DatePipe . I want to get the date and time in the following format dd-mm-yyyy hh:MM:ss AM/PM I got the expected by using the Angular DatePipe as follows <p>{{today | date:'dd-MM-yyyy hh:mm:ss a':'+0530'}}</p> output : 10-05-2018 03:28:57 PM Here I What I want to do is get the same output from my app.component.ts without touching the HTML's So I tried the below code but it generates a 13 digit

Angular 2 Datepipe formatting based on browser location/settings

大城市里の小女人 提交于 2020-01-04 04:08:07
问题 Is there a way to make the datepipe dynamic so that if it's an American browser the datepipe returns the American format (yyyy/MM/dd) and when it's a European browser it returns the European format (dd/MM/yyyy)? Thanks 回答1: This can be hard, especially when using aot. It would normally require you to make different builds. I extended the datapipe and use the browsers locale. Datepipe: @Pipe({name: 'datepipe', pure: true}) export class MyDatePipe extends DatePipe implements PipeTransform {

Angular DatePipe - Convert seconds to time with zero timezone

孤人 提交于 2019-12-23 15:38:35
问题 I want to convert number (which represents seconds) using DatePipe to get result like this : 00:00:05 I've tried doing so with DatePipe this way: <label>No timezone (default) {{ 5 * 1000 | date:'h:mm:ss'}}</label> But it produces result with timezone +4 included (which is not what I want): 4:00:05 So in order to avoid this I'm trying to set timezone offset to 0: <label>{{ 5 * 1000 | date:'h:mm:ss z':'+0000'}}</label> <label>{{ 5 * 1000 | date:'h:mm:ss z':'UTC'}}</label> <label>{{ 5 * 1000 |

Using Angular's Date Pipe on Input with 2-Way Binding

假装没事ソ 提交于 2019-12-08 07:46:49
问题 I am aware of how to use Angular's date pipe with typical string interpolation examples and/or for loops. However, I have a situation that's different than both these scenarios - where I've created a kind of custom two-way binding in my Angular 2 app. This is what my template code looks like: <input class="app-input [(inputModel)]="staff.profile.hireDate" placeholder="None" [field-status]="getPropertyStatus('profile.hireDate')"/> Is there a way I can pass the date pipe in here? I've tried

Angular 4 date pipe, no timezone

妖精的绣舞 提交于 2019-12-07 11:55:12
问题 I'm using date pipe to display record date to user on front-end. Back-end get's the date from DB and through rest I'm getting this from server to front-end. And there I use : <div>{{myDate | date:'dd-MM-yyyy HH:mm:ss'}}</div> The problem is, this time is with my own timezone witch I don't want. I need it to be the date exactly the same as I got from the server. PS. I can't use something like that : let myDataWithoutLocal = formatMyDate(myDate); because date comes in multiple object's, so I

Angular2 date pipe automatically adding timezone to date

a 夏天 提交于 2019-12-07 06:30:23
问题 I have a date string, like this 1987-06-15T00:00:00.000Z , when I am added date pipe on it the date is showing a different date like Jun 14, 1987 in American time zone, but in India, it's showing correct. <div>{{'1987-06-15T00:00:00.000Z' | date}}</div> 回答1: The string 1987-06-15T00:00:00.000Z represents different dates in different browser time zones. Fix If you don't want to change the date based on time zone, just use string parsing (e.g. substr ) and not date parsing. 回答2: This code is

Angular 4 date pipe, no timezone

北慕城南 提交于 2019-12-05 20:18:58
I'm using date pipe to display record date to user on front-end. Back-end get's the date from DB and through rest I'm getting this from server to front-end. And there I use : <div>{{myDate | date:'dd-MM-yyyy HH:mm:ss'}}</div> The problem is, this time is with my own timezone witch I don't want. I need it to be the date exactly the same as I got from the server. PS. I can't use something like that : let myDataWithoutLocal = formatMyDate(myDate); because date comes in multiple object's, so I would really like to modify the pipe, than the object or it's data. Try this:- <!--output '2015-06-15 09

Angular2 date pipe automatically adding timezone to date

﹥>﹥吖頭↗ 提交于 2019-12-05 10:22:32
I have a date string, like this 1987-06-15T00:00:00.000Z , when I am added date pipe on it the date is showing a different date like Jun 14, 1987 in American time zone, but in India, it's showing correct. <div>{{'1987-06-15T00:00:00.000Z' | date}}</div> The string 1987-06-15T00:00:00.000Z represents different dates in different browser time zones. Fix If you don't want to change the date based on time zone, just use string parsing (e.g. substr ) and not date parsing. This code is worked for me <div>{{date_of_birth.split("T")[0] | date}}</div> 来源: https://stackoverflow.com/questions/45582333

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

时光怂恿深爱的人放手 提交于 2019-11-28 09:39:33
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. 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 module's providers: NgModule({ providers: [DatePipe] }) export class AppModule { } or component's providers:

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

≡放荡痞女 提交于 2019-11-27 19:45:29
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 Argentina and we have GMT-3 then 00:00 of the 31st minus 3 hours would be May 30 at 9 PM. So how can I make