插入记录时 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 at 22.00pm)。
怎么改时间??
谢谢!!!
您需要更改语言环境或仅更改时区。
- 您可以更改当前日期对象的区域设置或时区,并且
使用 DatePipe.
手动将其转换为您的需要
首先你需要在你的 app.module 文件中导入 DatePipe
import { DatePipe } from '@angular/common';
将其添加到@NgModule 中的提供者。
providers: [DatePipe]
在component.ts中:
导入组件。
import { DatePipe } from '@angular/common';
将其添加到构造函数中。
constructor(private datePipe: DatePipe){}
然后你可以做这样的事情。这会将日期转换为时区 GMT+2.00。
dateObject = new Date();
formattedDate = this.datePipe.transform(this.dateObject, 'full', '+200');
您可以实时查看示例 here。
澄清一下。 DatePipe 有 3 个参数(格式、时区、语言环境),您可以这样调用它们。
this.myPipe.transform(myData, arg1, arg2, arg3)
你也可以像这样在 html 中用管道格式化:
{{ myData | myPipe: 'arg1':'arg2':'arg3'... }}
因此,为了制作正确的日期格式,您可以尝试使用参数。
如果您想进行全局更改,您可以检查:
- Setting up your app locale
- 你也可以查看这个
对日期和时间使用moment.js,它提供了如下各种日期和时间功能:
moment.js 有不同的方法来获取必要格式的时间和日期。
今天=时刻()
如果你想要特定的日期格式,那么你使用like
today=moment().format('DD/MM/YYYY')
console.log('Today Date with format e.g 24/07/2018
:',moment().format('DD/MM/YYYY'))
您需要使用以下命令安装 moment :
第一步:npm i moment --save
第 2 步:从 'moment'; //in your component code.
导入 * 作为时刻
在我的应用程序中,我有一个页面可以插入带有 属性 'performedOn' 的记录。当插入带有日期 (24/07) 的记录时,时间是 00.00am,但保存时 GTM 实际上是 -2.00,日期更改为 (23/07 at 22.00pm)。 怎么改时间?? 谢谢!!!
您需要更改语言环境或仅更改时区。
- 您可以更改当前日期对象的区域设置或时区,并且 使用 DatePipe. 手动将其转换为您的需要
首先你需要在你的 app.module 文件中导入 DatePipe
import { DatePipe } from '@angular/common';
将其添加到@NgModule 中的提供者。
providers: [DatePipe]
在component.ts中:
导入组件。
import { DatePipe } from '@angular/common';
将其添加到构造函数中。
constructor(private datePipe: DatePipe){}
然后你可以做这样的事情。这会将日期转换为时区 GMT+2.00。
dateObject = new Date();
formattedDate = this.datePipe.transform(this.dateObject, 'full', '+200');
您可以实时查看示例 here。
澄清一下。 DatePipe 有 3 个参数(格式、时区、语言环境),您可以这样调用它们。
this.myPipe.transform(myData, arg1, arg2, arg3)
你也可以像这样在 html 中用管道格式化:
{{ myData | myPipe: 'arg1':'arg2':'arg3'... }}
因此,为了制作正确的日期格式,您可以尝试使用参数。
如果您想进行全局更改,您可以检查:
- Setting up your app locale
- 你也可以查看这个
对日期和时间使用moment.js,它提供了如下各种日期和时间功能:
moment.js 有不同的方法来获取必要格式的时间和日期。
今天=时刻()
如果你想要特定的日期格式,那么你使用like
today=moment().format('DD/MM/YYYY')
console.log('Today Date with format e.g 24/07/2018
:',moment().format('DD/MM/YYYY'))
您需要使用以下命令安装 moment :
第一步:npm i moment --save
第 2 步:从 'moment'; //in your component code.