最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Setting a default time using Pikaday - Stack Overflow

programmeradmin0浏览0评论

I'm using Owen Meads fork of Pikaday, which includes time selection (can be found here). Is there a way to set the default time for the time-picker using JavaScript?

Here is what I have so far:

 var timepicker = new Pikaday({
            field: document.getElementById('<%= datetimepicker.ClientID %>'),
            firstDay: 1,
            minDate: new Date(2000, 0, 1),
            maxDate: new Date(2100, 12, 31),
            yearRange: [2000, 2100],
            showTime: true,
            autoClose: true,
            timeLabel: "Time In Work: ",
            use24hour: true,
            incrementMinuteBy: 5,
            format: 'DD-MMM-YYYY HH:mm',
            disableDayFn: function(date) {
                return moment().isBefore(moment(date), 'day');
            }
 });

If not, how may I get around something like this? I have never forked a project from Github before and I am unsure where to start.

I'm using Owen Meads fork of Pikaday, which includes time selection (can be found here). Is there a way to set the default time for the time-picker using JavaScript?

Here is what I have so far:

 var timepicker = new Pikaday({
            field: document.getElementById('<%= datetimepicker.ClientID %>'),
            firstDay: 1,
            minDate: new Date(2000, 0, 1),
            maxDate: new Date(2100, 12, 31),
            yearRange: [2000, 2100],
            showTime: true,
            autoClose: true,
            timeLabel: "Time In Work: ",
            use24hour: true,
            incrementMinuteBy: 5,
            format: 'DD-MMM-YYYY HH:mm',
            disableDayFn: function(date) {
                return moment().isBefore(moment(date), 'day');
            }
 });

If not, how may I get around something like this? I have never forked a project from Github before and I am unsure where to start.

Share Improve this question edited Sep 15, 2017 at 8:25 Nilesh Khisadiya 1,6782 gold badges16 silver badges28 bronze badges asked Sep 15, 2017 at 8:21 BingobangoBingobango 331 silver badge9 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

Use the setDate method.

timepiker.setDate()

EDIT

Like this:

var timepicker = new Pikaday({
  field: document.getElementById('<%= datetimepicker.ClientID %>'),
  firstDay: 1,
  minDate: new Date(2000, 0, 1),
  maxDate: new Date(2100, 12, 31),
  yearRange: [2000, 2100],
  showTime: true,
  autoClose: true,
  timeLabel: "Time In Work: ",
  use24hour: true,
  incrementMinuteBy: 5,
  format: 'DD-MMM-YYYY HH:mm',
  disableDayFn: function(date) {
    return moment().isBefore(moment(date), 'day');
  }
});
timepicker.setDate(new Date('14-Sep-2017 09:00:00'));

When I worked with Pikaday package in Vue.Js project I had to set default date to my date field in form. I tried many different versions of setting default date. But they didn't work for me. Finally I found the solution for my situation. The solution was to set prop like auto-default="autoDefault" here autoDefault is equels to true to Pikaday ponent like this...

<vue-pikaday v-model='date' auto-default="autoDefault" :options="pikadayOptions" />

 data() {
    return {
       autoDefault : true,
       pikadayOptions: {
           format  : 'YYYY/MM/DD',
           minDate : moment().toDate(),
       },
   }
},
发布评论

评论列表(0)

  1. 暂无评论