插入记录时,Angular2时间不正确。如何提高GTM + 2.00的价值? [英] Angular2 Time incorrect when I insert a record. How can I impost GTM+2.00?
问题描述
在我的应用中,我有一个页面可以插入具有 performedOn属性的记录。当插入记录的日期为日期(24/07)时,时间为00.00am但保存时GTM为-2.00有效,日期更改为(23/07在22.00pm)。
如何更改时间?
谢谢!!!
In my app I have a page were can insert a record with a property 'performedOn'. when insert record whit a date(24/07), the time is 00.00am but the GTM is -2.00 infact when save, date change in (23/07 at 22.00pm). How can I change time?? Thank!!!
推荐答案
您需要更改语言环境或仅更改时区。
You need to change the locale or just the timezone.
- 您可以更改当前日期对象的语言环境或时区,然后
可以使用 DatePipe 。
- You can change the locale or timezone of your current date object and transform it manually to your needs by using a DatePipe.
首先,您需要从您的app.module文件中导入DatePipe
First you need to import DatePipe in your app.module file
import { DatePipe } from '@angular/common';
将其添加到@NgModule中的提供程序中。
Add it to the providers in @NgModule.
providers: [DatePipe]
在component.ts中:
In component.ts:
导入组件。
import { DatePipe } from '@angular/common';
将其添加到构造函数中。
Add it to the constructor.
constructor(private datePipe: DatePipe){}
然后您可以做这样的事情。
Then you can do something like this. This would transform the date to the timezone GMT+2.00.
dateObject = new Date();
formattedDate = this.datePipe.transform(this.dateObject, 'full', '+200');
您可以实时查看示例。
You can see the example live here.
进行澄清。 DatePipe 具有3个参数(格式,时区,语言环境),您可以像这样调用它们。
To clarify. DatePipe has 3 arguments (format, timezone, locale) and you can call them like this.
this.myPipe.transform(myData, arg1, arg2, arg3)
您也可以使用html格式的Pipe来格式化:
You can also format with the Pipe in the html like this:
{{ myData | myPipe: 'arg1':'arg2':'arg3'... }}
正确的日期格式可以使用参数。
So to make the right date format you can play around with the arguments.
如果要进行全局更改,可以检查:
If you want to make global changes you can check:
- 设置您的应用语言环境
- 您还可以检查此发布
- Setting up your app locale
- You can also check this post
这篇关于插入记录时,Angular2时间不正确。如何提高GTM + 2.00的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!