UI APIs

datePicker

Display a date picker dialog for selecting dates and times.

Overview

my.datePicker opens a date selection dialog that allows users to pick dates and times in various formats. By default, the current date and time are used if not manually selected.

Sample Code

my.datePicker({
  format: 'yyyy-MM-dd',
  currentDate: '2016-10-10',
  startDate: '2016-10-9',
  endDate: '2017-10-9',
  success: (res) => {
    my.alert({
      title: 'datePicker response: ' + JSON.stringify(res)
    });
  },
});

Parameters

PropertyTypeRequiredDescription
formatStringNoThe returned date format.
currentDateStringNoThe date and time initially selected. By default, the current time date and time are used.
startDateStringNoMinimum date and time.
endDateStringNoMaximum date and time.
successFunctionYesThe callback function for a successful API call.
failFunctionYesThe callback function for a failed API call.
completeFunctionYesThe callback function used when the API call is completed. This function is always executed no matter the call succeeds or fails.

Date Formats

The returned date formats include:

  • yyyy-MM-dd (default)
  • HH:mm
  • yyyy-MM-dd HH:mm
  • yyyy-MM
  • yyyy

Success Callback Function

PropertyTypeDescription
dateStringThe selected date.

Error Code

Error CodeDescriptionSolution
11The user cancels the operation and no action is required.The user cancelled the operation and no action is required.

Usage Notes

  • If currentDate, startDate, or endDate are not specified, the current date and time are used by default
  • The format parameter determines the date picker's mode and return format
  • Users can cancel the picker, which triggers the fail callback with error code 11