标签: angular-date-format

Angular 8将带有字符串日期的json响应转换为JS日期的方法?

我知道 json 不会以特殊方式处理日期,而是将它们作为服务器中的字符串提供。有没有办法提供具有 ISO 日期属性的 json 对象响应,并将其映射到已经将日期属性映射为 JS 日期的类?

例子:

杰森响应:

{
    "data": {
        "id": 1,
        "name": "John",
        "surname": "Smith",
        "birthDate": "1986-05-04T22:59:59.000Z"
        "subscriptionDate": "2020-06-28T14:36:43.498Z"
    }
}
Run Code Online (Sandbox Code Playgroud)

我有这样的课程:

export class User {

    id: string;
    name: string;
    surname: string;
    birthDate: Date;
    subscriptionDate: Date;

}
Run Code Online (Sandbox Code Playgroud)

我的服务方式:

getUser(id: string): Observable<User> {
    return this.http.get<User>(`${this.UrlService}estabelecimentos/${id}`, { headers: this.authenticationService.jwt() }).catch(super.serviceError);
}
Run Code Online (Sandbox Code Playgroud)

但是当我在组件中使用它时,birthDate 和 subscriptionDate 始终被视为字符串。有没有办法将其转换为 JS 日期,而不必通过迭代 json 响应并修改对象来格式化每个请求中的日期?

angular-date-format angular

7
推荐指数
1
解决办法
1万
查看次数

Angular custom date format adapted to locale

I need to display dates based on locale. All goes well when I use the predefined formats (https://angular.io/api/common/DatePipe#pre-defined-format-options)

import { formatDate } from '@angular/common';
...
//if `format` is one from the predefined ones, for example 'shortDate', it works fine
return formatDate(value, format, this.localeService.currentLocale);
Run Code Online (Sandbox Code Playgroud)

But I need to display only months and years, format which doesn't exist in the predefined ones, therefor I need to create a custom format and give it as a parameter to the formatDate function. …

datetime date-pipe angular-date-format angular

6
推荐指数
0
解决办法
655
查看次数

Angular-以字符串形式获取格式,用于根据语言环境显示日期

如何获取Angular用于显示日期的字符串形式的格式?我用的是date管道设置后,LOCALE_ID在我的app.module

现在,我想检索“ dd / mm / yyyy”字符串,以放入我的输入占位符。

基本上,这里描述的只是Angular。

谢谢

[编辑]

为了使它更明确,我没有在寻找一种格式化日期的方法,这种方法已经完成了(使用本机date管道)。我想要代表此管道正在使用的格式的字符串。

因为我希望我的日期选择器占位符像

“日期(格式:XXXXXX)”

我希望“ XXXXXX”部分正确(例如,法语为“ jj / mm / aaaa”,英语为“ mm / dd / yyyy”)

angular-date-format angular

5
推荐指数
1
解决办法
2197
查看次数

角度2日期管道周数

我查询了如何在Angular 2中返回星期数。我没有找到这个问题的答案。我确实在https://docs.angularjs.org/api/ng/filter/date上发现在Angular 1中会是这样的:{{today | date:'w'}}但是这似乎在Angular 2中不起作用。我知道我可以编写一个函数来解决这个问题,但这似乎不切实际。我是否在有关Angular 2的文档中丢失了某些内容,或者尚未在其中实现?

angular-date-format angular

3
推荐指数
1
解决办法
5955
查看次数

Angular 5 - 如何在DatePipe中使句点字段类型为小写

在Angular 5.1中使用DatePipe,我需要以小写形式格式化句点字段类型(AM/PM).根据文件,

Tuesday, December 19, 7:00 am 
Run Code Online (Sandbox Code Playgroud)

应该

date:'EEEE, MMMM d, h:mm a'
Run Code Online (Sandbox Code Playgroud)

但是,句点字段类型始终以大写形式显示,所以我看到:

Tuesday, December 19, 7:00 AM
Run Code Online (Sandbox Code Playgroud)

我做错了什么,或者这是Angular日期格式化的已知缺陷?

angular-pipe angular-date-format angular angular5

3
推荐指数
1
解决办法
2286
查看次数

如何将角度中的日期转换为另一个时区

我正在使用Date()本地时区获取当前时间。我已将其格式化如下:

this.today = new Date();
      from = new DatePipe('en-Us').transform(this.today, 'dd:MM:yyyy hh-mm-ss');
Run Code Online (Sandbox Code Playgroud)

现在我想将from日期时间转换Europe/London为时区。没有moment. 请帮我

angular-date-format angular

3
推荐指数
1
解决办法
1万
查看次数