I've tried in many ways. First I get the date as Moment.js object,
this.meeting.start = event.date.local().toDate();
I also tried the following:
this.meeting.start = new Date(this.meeting.start.toLocaleString());
my html:
<input
type="datetime-local"
class="form-control"
value="{{meeting.start}}"
[(ngModel)]="meeting.start" />
but the UI window is empty:"--:-- dd/mm/yy"
Thanks.
I've tried in many ways. First I get the date as Moment.js object,
this.meeting.start = event.date.local().toDate();
I also tried the following:
this.meeting.start = new Date(this.meeting.start.toLocaleString());
my html:
<input
type="datetime-local"
class="form-control"
value="{{meeting.start}}"
[(ngModel)]="meeting.start" />
but the UI window is empty:"--:-- dd/mm/yy"
Thanks.
Share Improve this question edited Sep 6, 2018 at 15:29 Aa Yy asked Sep 6, 2018 at 15:10 Aa YyAa Yy 1,7426 gold badges20 silver badges34 bronze badges4 Answers
Reset to default 3This works for me :
let today = new Date();
this.meeting.start = today.toISOString().split('T')[0]
in html
<input
type="date"
class="form-control"
value="{{meeting.start}}"
[(ngModel)]="meeting.start" />
please see example in https://angular-rb5vmu.stackblitz.io (last item : Input Date Format )
Edited!
Based on the help I got here, I managed to get this to work with this workaround:
var add = moment(this.meeting.start).add(3, 'hours');
var result = add.toISOString().split('.')[0];
this.meeting.start = result;
Try this
const fmt = 'HH:mm DD/MM/YY';
const result = moment.utc(this.meeting.start, fmt).local().format(fmt);
Template:
<input type="datetime-local" [value]="result">
Sample StackBlitz
This worked for me, I tried all the answers above but none worked..
// Init dates
let today = moment.utc().local().format('YYYY-MM-DDTHH:mm');
let todayMinus7Days = moment.utc().local().subtract(7, 'days').format('YYYY-MM-DDTHH:mm');
console.log(today);
console.log(todayMinus7Days);
And the result from the browser console is :
And the result is the browser itself is :