ng2-ui / datetime-picker

Angular2 DateTime Picker
https://ng2-ui.github.io/#/datetime-picker
MIT License
121 stars 62 forks source link

date-format not working? #5

Closed spalt closed 8 years ago

spalt commented 8 years ago

Is it just me or is it doing yMd even when you specify something else? <input [(ngModel)]="date2" datetime-picker date-format="Mdy" date-only="true" /> still shows as 2015-01-01

allenhwkim commented 8 years ago

Sorry, at the beginning, date-format was implemented but removed because of Angular2 date pipe limit and IE bugs. Thus, current date-format is not working and we will make it better in the future.

spalt commented 8 years ago

no problem! i forked your repo and made a change for my needs for now.

allenhwkim commented 8 years ago

If you find a general solution for date formatting, I am be very interested in.

cyberbobjr commented 8 years ago

Hi, i'm interested to format date, do you have any solution ? thanks you, best regards

allenhwkim commented 8 years ago

There is a plan to implement this one, but at this moment it's not a simple solution. That's why I do not implement this one yet.

Currently ngModel should be a string, but to format properl;

  1. a string should be changed to a date ( parsing is required here )
  2. generated formatted string from date
  3. replace string with formatted one

Idea 1

1.ngModel as string as it is

  1. custom parser
  2. custom formatter

idea 2

  1. ngModel as string as it is
  2. moment js formatter

idea 3

  1. ngModel as a "Date", not a string
  2. moment.js formatter or date pipe format

Each idea has its own pros and cons.

josepoma commented 8 years ago

Hi @allenhwkim , I try idea3, but not working.

Component import * as moment from 'moment'; ..... executeDateStart= moment().format('L'); console.log(executeDateStart); // 05/08/2016 :+1:

HTML <input class="form-control" [(ngModel)]="executeDateStart" name="executeDateStart" ng2-datetime-picker date-only="true" />

the format shown remains yyyy-MM-dd :-1:

:(

allenhwkim commented 8 years ago

@josepoma

Formatting date is provided by DateTime service https://github.com/ng2-ui/ng2-datetime-picker/blob/6b57d25ef3f065055551d245b9fc3033163e0dab/dist/datetime.ts#L91

And it is used by DateTimePicker Directive https://github.com/ng2-ui/ng2-datetime-picker/blob/6b57d25ef3f065055551d245b9fc3033163e0dab/dist/datetime-picker.directive.ts#L67

So, if you follow idea 3, you need to change those codes.

allenhwkim commented 8 years ago

date-format is not enabled with the help of moment.js. Idea 3 has been implemented

faridabbas-dl commented 6 years ago

Yes. thanks for help everyOne...... for me I included moment.js in my index file its working fine for me. if i ignore this then i must ignore the date-formate also to activate functionality ... including the date-format i can see the calendar but cannot see date i selected in the input box...