1

For example Jun 13 2003 23:11:52.454 UTC in epoch date format is 1055545912454. But when I pass this value in bsValue I get undefined.

Requirement my requirement are that date should be sent in epoch format in the api while making a server request. So, I have written a directive which converts any date format to milliseconds(changeDateDirective) and when this happens bsdatepicker returns undefined <input changeDateDirective type="text" placeholder="Datepicker" class="form-control" #dp="bsDatepicker" bsDatepicker [(bsValue)]="bsValue" [minDate]="bsValue" [bsConfig]="{ showWeekNumbers:false, selectFromOtherMonth: true}" > The same works in angular ui datepicker(uib-datepicker - https://angular-ui.github.io/bootstrap/)

1 Answers1

0

bsValue expects an object of Javascript's Date, so you have to pass a Date instance. A Date instance can be constructed with a Unix Time Stamp(number of milliseconds since January 1, 1970, 00:00:00 UTC)

let date = new Date(1055545912454);
// Date 2003-06-13T23:11:52.454Z
bsValue = date;
wuarmin
  • 3,274
  • 3
  • 18
  • 31
  • Thanks but my requirement are that date should be sent in epoch format in the api while making a server request. So, I have written a directive which converts any date format to milliseconds(dateToMillis) and when this happens bsdatepicker returns undefined The same works in angular ui datepicker(uib-datepicker) – Rahul K Pandey Jan 31 '19 at 08:06
  • Why you are not just converting Dates into Unix Time Stamps shortly before sending it to backend(i.e. at serializer)? – wuarmin Jan 31 '19 at 08:13
  • Because we will have to convert it again and again wherever we use datepicker, Instead I wanted a generic solution and hence the directive – Rahul K Pandey Jan 31 '19 at 08:15
  • Then just wrap your ngx-bootstrap-datepicker in a component. Then you can handle the convert there and can reuse the component everywhere in your app. – wuarmin Jan 31 '19 at 08:19
  • I can try that. Thanks !! – Rahul K Pandey Jan 31 '19 at 08:20
  • for time being I have used this solution https://stackoverflow.com/questions/46159487/how-to-change-the-date-format-in-the-datepicker-of-angular-ngx-bootstrap-inside. – Rahul K Pandey Feb 07 '19 at 14:03