Asked  9 Months ago    Answers:  5   Viewed   12 times

I have a fiddle which displays date picker. same code i have written below but nothing happens, what wrong i am doing? When i click on that green colour then no date picker is generated, but in fiddle it is coming fine, where i am doing wrong?

http://jsfiddle.net/cBwEK/10/

  <html>
   <head>
 <script type="text/javascript" src="mootools-yui-compressed.js"></script>//mootools script  
    <script type="text/javascript" src="datepicker.js"></script>     
    <link rel="stylesheet" type="text/css" href="datepicker.css" />

   </head>
   <body>

  <input name='date_allow_empty' type='text' value='' class='date picker' />
  <div id="invokeDP"></div>

      <script type="text/javascript">           
       var dp = new DatePicker('.picker', {
  pickerClass: 'datepicker ',
  allowEmpty: true,
  toggleElements: ['invokeDP']
  });    
     </script>  

   </body>
</html>

EDIT: I have taken all scripts inside head section, previously these scripts were in body section

 Answers

3

I think you miss a mootools core library.

<script src="http://fiddle.jshell.net/js/lib/mootools-core-1.4.5-nocompat.js"></script>

Here is my working solution http://jsbin.com/unosar/4/edit#source (click at Render button to preview)

Thursday, September 2, 2021
 
moister
 
1

I'm still learning JavaScript, and the only way that I've found which works for me to compare two dates without the time is to use the setHours method of the Date object and set the hours, minutes, seconds and milliseconds to zero. Then compare the two dates.

For example,

date1 = new Date()
date2 = new Date(2011,8,20)

date2 will be set with hours, minutes, seconds and milliseconds to zero, but date1 will have them set to the time that date1 was created. To get rid of the hours, minutes, seconds and milliseconds on date1 do the following:

date1.setHours(0,0,0,0)

Now you can compare the two dates as DATES only without worrying about time elements.

Tuesday, June 1, 2021
 
3

Use the DatePicker

http://developer.android.com/reference/android/widget/DatePicker.html

It is availible since API Level 1

Here a example how to use the DatePickerDialog.

First add a TextView and a Button to your layout.xml

<Button android:id="@+id/myDatePickerButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Choose Date"/>

<TextView android:id="@+id/showMyDate"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"/>

Next you have to initialize the Button and TextView in the onCreate Method of your layout. You need this class variables

private int mYear;
private int mMonth;
private int mDay;

private TextView mDateDisplay;
private Button mPickDate;

static final int DATE_DIALOG_ID = 0;

Here the onCreate method

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mDateDisplay = (TextView) findViewById(R.id.showMyDate);        
    mPickDate = (Button) findViewById(R.id.myDatePickerButton);

    mPickDate.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showDialog(DATE_DIALOG_ID);
        }
    });

    // get the current date
    final Calendar c = Calendar.getInstance();
    mYear = c.get(Calendar.YEAR);
    mMonth = c.get(Calendar.MONTH);
    mDay = c.get(Calendar.DAY_OF_MONTH);

    // display the current date
    updateDisplay();
}

UpdateDisplay method:

private void updateDisplay() {
    this.mDateDisplay.setText(
        new StringBuilder()
                // Month is 0 based so add 1
                .append(mMonth + 1).append("-")
                .append(mDay).append("-")
                .append(mYear).append(" "));
}

The callback listener for the DatePickDialog

private DatePickerDialog.OnDateSetListener mDateSetListener =
    new DatePickerDialog.OnDateSetListener() {
        public void onDateSet(DatePicker view, int year, 
                              int monthOfYear, int dayOfMonth) {
            mYear = year;
            mMonth = monthOfYear;
            mDay = dayOfMonth;
            updateDisplay();
        }
    };

The onCreateDialog method, called by showDialog()

@Override
protected Dialog onCreateDialog(int id) {
   switch (id) {
   case DATE_DIALOG_ID:
      return new DatePickerDialog(this,
                mDateSetListener,
                mYear, mMonth, mDay);
   }
   return null;
}

Hope it helps, used it and it works fine.

Example from

http://developer.android.com/guide/tutorials/views/hello-datepicker.html

Tuesday, June 29, 2021
 
3

The fail is trying on concatenate the values, test with something like this:

let initialdate = '2016-10-01';
let start_time = '19:04:10';
let enddate = '2016-10-01';
let end_time = '19:04:20';

let datetimeA = moment(initialdate + " " + start_time);
let datetimeB = moment(enddate + " " + end_time);

console.log(datetimeA.format());
console.log(datetimeB.format());

let datetimeC = datetimeB.diff(datetimeA, 'seconds');

console.log(datetimeC);
Thursday, October 28, 2021
 
ericj
 
1

You can do it like this:

function createPickers(context) {
  $(".datefield", context || document).datepicker({
    showAnim:'fadeIn',
    dateFormat:'dd/mm/yy',
    changeMonth:true,
    changeYear:true
  });
}

To run on document.ready, if you already have a document.ready function you can call:

createPickers();

Or you can run it in it's own document.ready handle, like this:

$(createPickers);

In your success callback you call it like this:

createPickers(responseText);

What this does is only select .datefield in the provided context (internally this uses .find()), so on document.ready you're selecting all matching elements to create date pickers, but in your ajax request, you're selecting only the matching elements that just arrived in the response, not creating duplicate date pickers anywhere.

Sunday, November 14, 2021
 
b24
 
b24
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :