DateTime - default to todays date


I have the same problem. My date is always showed with a day less. I tried moment (, pipe “date: “dd/MM/yyyy””, but didn´t work. It is funny, because, the value in data base is correct, but when I try to format the date, a date with a less day is showed.


yes, i still didn’t solve this issue. i don’t know what to do…


I solve this:

In a .ts file:


     var dateParts = datepar.split("-");
     var date = new Date(dateParts[0], dateParts[1] - 1, dateParts[2]);
     return date;

In the .html

You can see more details about the this problem here

Good luck!


thank u,
what is datepar in your project? date selected?


datepar = date parameter… Just used for the example.


To get the ISO string and set the timezone, you can use this function (taken from this Stack Overflow post)

var tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds
var localISOTime = (new Date( - tzoffset)).toISOString().slice(0,-1);

Ion-datetime placeholder not working

Anyone know how to get the hour and minute separately?
I have this:

    PickerFormat = "HH: mm"
    [(NgModel)] = "time"
    CancelText = "Cancel"
    DoneText = "OK">

Which saves a string in my variable time when selecting a schedule. I need to get hours and minutes apart. Can not it be that instead of saving a string, I keep a Date object or something like that?


+1. Would like to have a property to set default picker date when it slides up or at least to be the current date\time.
I also have trouble as @sdrew, I’m using reactive forms and have optional dates and don’t want to make them required.


I want to customize date in ionic 2.
I want to add 3 days in today’s date

For Example if today is 5 August it should display 8 august.

How i can customize it ?




@rapropos this date-fns not working on my side after installing “npm install date-fns --save”.

I am using typescript in ionic 2.

Do you know why it is not adopting this library ?


No, because it works for me, so you would have to share your code for anybody to be able to say anything constructive.



in .ts file i am getting date like this
myDate: String = new Date().toISOString();

and in .html file
" ion-datetime displayFormat=“YYYY/MM/DD” pickerFormat=“YYYY MMMM DDDD” min=“2017” [(ngModel)]=“myDate” name=“booking_date”></ion-datetime "


I am not seeing anywhere in what you posted where you call anything from date-fns.


i found out the solution

new Date(new Date().getTime()+(32460601000)).toISOString();
in this I am adding 3 days in the actual date


OK, whatever. The entire point of libraries like date-fns is to eliminate the need for such ugliness as (3*24*60*60*1000), but if you’re not sufficiently motivated to get it to work and are happy with that, it’s not my business.


new Date().toISOString() is returning wrong time. It does not calculate the timezone I suppose.
Any idea how to fix this.
I am trying on simulator and time in simulator is 11:40 AM but Date object returns 9:40 AM

Calendar for scheduling app

Javascript time library does not manage time correctly.
I recommend using moment.js.
go to you folder application, run : npm install moment --save
in your page.ts add: import * as moment from ‘moment’;
declare your variable: myDate= moment().format();

Now just use ion-datetime like this:

                <ion-datetime type="datetime-local" displayFormat="MMM, YYYY" max="2099-12-31" [(ngModel)]="myDate"  ></ion-datetime>

I hope this helps.


This answer is spot on


Hello, your solution helped me. Would you like to know if you can put this result inside an object? Has an obejto receiving date:

Test = {data: ‘’, value: ‘’};

I tried to put

Test = {data: moment (). Format (), value: ‘’};

but it does not work