angular - Angular - 无效的日期时间格式:1292 日期值不正确
问题描述
我正在开发一个客户端门户应用程序。Laravel-5.8 是后端,Angular-7 是前端。我正在使用 POST REQUEST。
客户报价-landing.component.ts
import { Component, OnInit, Inject, LOCALE_ID, TemplateRef } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { ClientQuoteService } from '../../../../shared/services/client-quote.service';
import { first } from 'rxjs/operators';
import { ToastrService } from 'ngx-toastr';
import { formatDate } from '@angular/common';
import { Validators, FormBuilder, FormGroup, FormControl } from '@angular/forms';
@Component({
selector: 'app-client-quote-landing',
templateUrl: './client-quote-landing.component.html',
styleUrls: ['./client-quote-landing.component.scss']
})
export class ClientQuoteLandingComponent implements OnInit {
quoteModel: any = {};
formattedAddress = '';
truck_types = [];
constructor(
private clientQuoteService: ClientQuoteService, private toastr: ToastrService,
private router: Router,
@Inject(LOCALE_ID) private locale: string,
private route: ActivatedRoute
) {
}
ngOnInit() {
window.dispatchEvent(new Event('load'));
window.dispatchEvent(new Event('resize'));
}
客户报价-landing.component.html
<form name="quote" #quoteform="ngForm" (ngSubmit)="onCreateQuote(quoteform);" method="post" novalidate>
<div class="row">
<div class="col-xs-12">
<div class="col-xs-6">
<label for="loading_date">Loading Date<span style="color:red;"> *</span></label>
<div class="input-group date">
<mat-form-field>
<input matInput [matDatepicker] = "picker" placeholder = "Choose a date" name="loading_date" [(ngModel)]="quoteModel.loading_date" #loading_date="ngModel" [ngClass]="{'is-invalid' : loading_date.invalid && ((loading_date.dirty || loading_date.touched) || quoteform.submitted)}" required>
<mat-datepicker-toggle matSuffix [for] = "picker"></mat-datepicker-toggle>
</mat-form-field>
<div class="form-feedback" *ngIf="loading_date.invalid && ((loading_date.dirty || loading_date.touched) || quoteform.submitted)">
<div style="color:red;" *ngIf="loading_date.errors?.required"class="alert alert-danger">Loading Date is required.</div>
</div>
</div>
</div>
</div>
</div>
<button style="margin:5px" type="submit" class="btn btn-success" > Get A Quote</button>
</form>
当我点击提交按钮时,什么都没有发生,然后我检查了网络,我收到了这个错误:
消息:“SQLSTATE [22007]:无效的日期时间格式:1292 不正确的日期值:'2019-09-26T23:00:00.000Z' 列
clientportal
.client_quotes
.loading_date
在第 1 行(SQL:插入client_quotes
(first_name
,last_name
,phone
,business_name
,address
,comment
,truck_type
,truck_required
,quote_origin
,quote_destination
,commodity
,loading_date
,updated_at
,created_at
) 值(Michael, Idowu, noblemfd@yahoo.com, 33334444444444, jolamic, ddsds, dd, Residential, 2, ddds, ssa, ee, 2019-09-26T23:00:00.000Z, 2019- 09-19 00:53:55, 2019-09-19 00:53:55))”
在 MySQL 数据库中,loading_date数据类型是日期。
如何解决此错误?
解决方案
将loading_date 数据类型更改为varchar(20),错误是因为您选择了错误的数据类型。
推荐阅读
- c# - 匿名管道 c# WPF
- ruby-on-rails - Rails 6 在为获取 Module#parent 的 javascript 测试用例执行茶匙时已重命名为 `module_parent`
- simulink - 如何在 Simulink 中抵消时间值?
- node.js - 电子上的 ioHook 消耗过多的 CPU。反正周围有吗?或替代 ioHook
- python - ping minecraft 服务器的 Discord 机器人。Python
- angular - 如何使用 Angular 自定义 Web 组件设置顺风
- reactjs - React Bootstrap Slider 动态设置属性
- c++ - CPP chrony io 代码在一台计算机上冻结,但在另一台计算机上冻结
- javascript - 电话号码验证器
- amazon-web-services - Jenkins 管道:AWS EKS - EC2MetadataError:未能发出 EC2Metadata 请求状态代码:404