格式化垫子datepicker Angular并发送到节点JS
我想将日期发送到存储日期,但2022-04-26T18:30:00.000Z
这是我要获得的格式,我想像26-04-2022
我的Angular HTML
<mat-form-field color="accent" appearance="fill">
<mat-label>Custom calendar color</mat-label>
<input matInput [matDatepicker]="picker2">
<mat-datepicker-toggle matSuffix [for]="picker2"></mat-datepicker-toggle>
<mat-datepicker #picker2 color="primary"></mat-datepicker>
</mat-form-field>
应该如何更改它,应该在Angular
或node.js
api上进行。确切地说,我正在从Angular发送更多值,例如拥有一些额外的输入框并以形式值发送。如果我想在API中执行此操作,我应该如何将日期和格式化为
我的api </
app.post('/path', function (req, res){
var data = req.body;
var onedata;
fs.readfile('filepath', 'utf8', function(err, data){
if(data){
onedata = JSON.parse(data)
onedata.push(data)
}
fs.writefile('filepath', 'utf8', function(err, data){
if(err){
throw err;
res.send("success");
}
strong API是我在文件中写的
full html html angular的方式
<form>
<mat-form-field appearance="outline">
<mat-label>Outline form field</mat-label>
<input matInput placeholder="Placeholder">
<mat-icon matSuffix>sentiment_very_satisfied</mat-icon>
<mat-hint>Hint</mat-hint>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Outline form field</mat-label>
<input matInput placeholder="Placeholder">
<mat-icon matSuffix>sentiment_very_satisfied</mat-icon>
<mat-hint>Hint</mat-hint>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Outline form field</mat-label>
<input matInput placeholder="Placeholder">
<mat-icon matSuffix>sentiment_very_satisfied</mat-icon>
<mat-hint>Hint</mat-hint>
</mat-form-field>
<mat-form-field color="accent" appearance="fill">
<mat-label>Custom calendar color</mat-label>
<input matInput [matDatepicker]="picker2">
<mat-datepicker-toggle matSuffix [for]="picker2"></mat-datepicker-toggle>
<mat-datepicker #picker2 color="primary"></mat-datepicker>
</mat-form-field>
</form>
I wanna send date to node to store but 2022-04-26T18:30:00.000Z
this is the format I am getting I wanna get like this 26-04-2022
My Angular HTML
<mat-form-field color="accent" appearance="fill">
<mat-label>Custom calendar color</mat-label>
<input matInput [matDatepicker]="picker2">
<mat-datepicker-toggle matSuffix [for]="picker2"></mat-datepicker-toggle>
<mat-datepicker #picker2 color="primary"></mat-datepicker>
</mat-form-field>
how should I change it should I do it in angular
or on node.js
API. To be precise I am sending more values from angular like having some extra Input box and sending as form value. If I wanna Do this in api how should i separate the date and format it
My API
app.post('/path', function (req, res){
var data = req.body;
var onedata;
fs.readfile('filepath', 'utf8', function(err, data){
if(data){
onedata = JSON.parse(data)
onedata.push(data)
}
fs.writefile('filepath', 'utf8', function(err, data){
if(err){
throw err;
res.send("success");
}
above api is how i wrote in my file
Full HTML angular for reference
<form>
<mat-form-field appearance="outline">
<mat-label>Outline form field</mat-label>
<input matInput placeholder="Placeholder">
<mat-icon matSuffix>sentiment_very_satisfied</mat-icon>
<mat-hint>Hint</mat-hint>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Outline form field</mat-label>
<input matInput placeholder="Placeholder">
<mat-icon matSuffix>sentiment_very_satisfied</mat-icon>
<mat-hint>Hint</mat-hint>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Outline form field</mat-label>
<input matInput placeholder="Placeholder">
<mat-icon matSuffix>sentiment_very_satisfied</mat-icon>
<mat-hint>Hint</mat-hint>
</mat-form-field>
<mat-form-field color="accent" appearance="fill">
<mat-label>Custom calendar color</mat-label>
<input matInput [matDatepicker]="picker2">
<mat-datepicker-toggle matSuffix [for]="picker2"></mat-datepicker-toggle>
<mat-datepicker #picker2 color="primary"></mat-datepicker>
</mat-form-field>
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想安装MOMM JS,
它将帮助您格式化日期,但是您希望在这里看到更多 - &gt;&gt;
moment js
You want to install moment js
It will help you to format your date however you want You can see more here --->>
moment js