Top Related Projects
lightweight, powerful javascript datetimepicker with no dependencies
A refreshing JavaScript Datepicker — lightweight, no dependencies, modular CSS
A datepicker for twitter bootstrap (@twbs)
JavaScript Date Range, Date and Time Picker Component
Quick Overview
DatePicker is a lightweight, customizable date picker component for web applications. It provides an easy-to-use interface for selecting dates, with support for various date formats and localization options.
Pros
- Simple and intuitive user interface
- Customizable appearance and behavior
- Lightweight with minimal dependencies
- Support for multiple date formats and localization
Cons
- Limited documentation and examples
- Lack of advanced features like date range selection
- No built-in time picker functionality
- Limited browser compatibility information
Code Examples
- Basic usage:
const datepicker = new DatePicker('#date-input', {
format: 'yyyy-mm-dd',
minDate: '2023-01-01',
maxDate: '2023-12-31'
});
This code initializes a DatePicker instance for an input element with the ID 'date-input', setting the date format and date range.
- Customizing appearance:
const datepicker = new DatePicker('#date-input', {
theme: 'dark',
weekStart: 1, // Monday
showWeekNumbers: true
});
This example creates a DatePicker with a dark theme, sets Monday as the first day of the week, and displays week numbers.
- Localization:
const datepicker = new DatePicker('#date-input', {
locale: 'fr',
monthNames: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'],
dayNames: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam']
});
This code sets up a DatePicker with French localization, including custom month and day names.
Getting Started
To use DatePicker in your project, follow these steps:
- Include the DatePicker CSS and JavaScript files in your HTML:
<link rel="stylesheet" href="path/to/datepicker.css">
<script src="path/to/datepicker.js"></script>
- Create an input element in your HTML:
<input type="text" id="date-input">
- Initialize the DatePicker in your JavaScript:
document.addEventListener('DOMContentLoaded', function() {
const datepicker = new DatePicker('#date-input', {
format: 'yyyy-mm-dd'
});
});
This will create a basic DatePicker instance for the input element with the ID 'date-input'.
Competitor Comparisons
lightweight, powerful javascript datetimepicker with no dependencies
Pros of flatpickr
- More feature-rich with extensive customization options
- Larger community and better documentation
- Supports multiple date selection and range picking
Cons of flatpickr
- Larger file size, which may impact page load times
- Steeper learning curve due to more complex API
- May be overkill for simple date picking needs
Code Comparison
DatePicker:
const datepicker = new DatePicker({
el: '#datepicker',
dateFormat: 'yyyy-mm-dd'
});
flatpickr:
flatpickr("#datepicker", {
dateFormat: "Y-m-d",
allowInput: true,
enableTime: true
});
Both libraries offer simple initialization, but flatpickr provides more options out of the box. DatePicker focuses on a streamlined approach, while flatpickr offers greater flexibility at the cost of complexity.
flatpickr is more suitable for projects requiring advanced date and time selection features, whereas DatePicker is ideal for simpler use cases where a lightweight solution is preferred.
Consider your project's specific needs, performance requirements, and development timeline when choosing between these date picker libraries.
A refreshing JavaScript Datepicker — lightweight, no dependencies, modular CSS
Pros of Pikaday
- More actively maintained with regular updates and bug fixes
- Extensive documentation and examples available
- Larger community support and wider adoption
Cons of Pikaday
- Larger file size and potentially more complex to implement
- May have unnecessary features for simpler use cases
Code Comparison
DatePicker:
const datepicker = new DatePicker({
el: document.getElementById('date-input'),
format: 'YYYY-MM-DD'
});
Pikaday:
const picker = new Pikaday({
field: document.getElementById('date-input'),
format: 'YYYY-MM-DD',
onSelect: function(date) {
console.log(date);
}
});
Summary
Pikaday offers a more robust and feature-rich solution with better community support and documentation. However, it may be overkill for simple date picking needs. DatePicker provides a more lightweight alternative but lacks the extensive features and ongoing maintenance of Pikaday. The choice between the two depends on the specific requirements of your project and the level of complexity you're willing to manage.
A datepicker for twitter bootstrap (@twbs)
Pros of bootstrap-datepicker
- More mature and widely adopted project with extensive documentation
- Offers a broader range of customization options and features
- Better integration with Bootstrap framework
Cons of bootstrap-datepicker
- Larger file size and potentially heavier performance impact
- May require more setup and configuration for basic use cases
Code Comparison
bootstrap-datepicker:
$('#datepicker').datepicker({
format: 'mm/dd/yyyy',
startDate: '-3d',
autoclose: true
});
DatePicker:
new DatePicker({
el: '#datepicker',
format: 'MM/DD/YYYY'
});
The code comparison shows that bootstrap-datepicker offers more configuration options in its initialization, while DatePicker has a simpler setup. bootstrap-datepicker uses jQuery syntax, whereas DatePicker uses vanilla JavaScript.
bootstrap-datepicker provides more advanced features out of the box, such as setting a start date and auto-closing the picker. DatePicker focuses on a more streamlined approach with fewer initial options.
Overall, bootstrap-datepicker is better suited for complex projects requiring extensive customization and Bootstrap integration. DatePicker may be preferable for simpler implementations or projects prioritizing lightweight solutions.
JavaScript Date Range, Date and Time Picker Component
Pros of daterangepicker
- More comprehensive feature set, including single date picker, date range picker, and time picker
- Extensive documentation and examples available
- Actively maintained with regular updates and bug fixes
Cons of daterangepicker
- Larger file size and potentially more complex implementation
- Dependency on Moment.js, which is no longer actively maintained
- May have a steeper learning curve for basic use cases
Code Comparison
DatePicker:
$('#datepicker').datepicker({
format: 'yyyy-mm-dd',
autoclose: true
});
daterangepicker:
$('input[name="daterange"]').daterangepicker({
startDate: moment().startOf('hour'),
endDate: moment().startOf('hour').add(32, 'hour'),
locale: {
format: 'YYYY-MM-DD hh:mm A'
}
});
The code comparison shows that daterangepicker offers more advanced functionality out of the box, such as setting start and end dates, and customizing the date format. However, this comes at the cost of increased complexity and the requirement of Moment.js. DatePicker provides a simpler implementation for basic date selection needs.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
You can jump to EN README after CN if you don't read chinese.
Here is begin of CN document.
æ¥åéæ©å¨
ç°å¸¸ç°å¸¸ç®åçAndroidæ¥åéæ©å¨ï¼æ³¨ï¼æä¸æ¯æ横å±æä½ï¼ååèæ°æä¸å°ä¸¤å¤©ç误差ï¼
Android API çæ¬è¦æ±
API 1
API 11
API 1
çæ¬è¿ä»£
1.0.0 beta
横å±ææªèèï¼ç«å±ææªåç°é®é¢ï¼é¡¹ç®ä½¿ç¨ä¸
1.1.2 release
- å¢å æ¥æéæ©æ¶å¼¹æ§å¨ç»
- ä¿®å¤è®¾ç½®ä¸»è²è°åååé¢è²ä¸æ¹åBUG
1.1.3 release
- ä¸ç®¡æ¯æ¨ªå±è¿æ¯ç«å±ï¼ä½ å¿ é¡»æ»ä¸ºè¯¥æ§ä»¶æå®ä¸ä¸ªç¡®å宽度æ¯å¦320dpæè å¡«å ç¶å¸å±ï¼å¤§å¤æ°æ åµä¸è¯¥æ¥æéæ©å¨é½æ¯å¨dialogä¸ä½¿ç¨ï¼é»è®¤dialog宽度æ¯å¡«å å±å¹å®½åº¦çï¼ä½ å¯ä»¥åç §Demoæ¥æ´æ¹diaologç宽度ã
2.0.0 stable LTS
- APIçæ¬æ¯æå°1ï¼å¯¹äºå¤§äºçäºAPI11ççæ¬æ¯æå¨ç»æ¾ç¤º
- å¢å å¼å£°å¾é«çåé模å¼æ¯æ ç®åæ¯æ两ç§æ¨¡å¼ åéåå¤é
- å¢å å¨æ¬¡æ é¢çæ¾ç¤º
- æ¯æä¸ä¸æ»å¨åæ¢å¹´ä»½ å·¦å³æ»å¨åæ¢æ份
- èæ¥ææ¬æ¾ç¤ºä»åè¡è°æ´ä¸ºä¸¤è¡
- è°æ´UIè²è°ç¬¦åmaterial design
- 对äºå¤©ææåï¼å¢å åæãè¡¥ä¼çæ è¯
- å¢å å¼å£°å¾é«ç对ä»å¤©æ¥æçæ è¯
- æ¯æé»è®¤å¹´æ设å®
- å¨ç°ææè§å¾çåºç¡ä¸åå²åºäºä¸ªåºåæä¾èªå®ä¹è£ 饰ç©çç»å¶
- å¨ç°ææè§å¾çåºç¡ä¸åå²åºä¸ä¸ªèæ¯å±æä¾èæ¯è£ 饰ç©çç»å¶
- å ç½®ä¸æåè±è¯ä¸¤ç§è¯è¨ï¼æ ¹æ®å½åç³»ç»è¯è¨ç¯å¢èªå¨åæ¢
- æ¯æèªå®ä¹å½å®¶è¯è¨æ©å±
- å ç½®ä¸å½åç¾å½ä¸¤å½èåæ¥æ¾ç¤º
- æ¯æå¤å½åæèæ¥æ¾ç¤ºæ©å±
- å¢å¼ºä¸»é¢è²è°æ©å±å®å¶æ´æäºæä½
- ä¼å天æåååèæ°ç®æ³ ååæ¾ç¤ºèå´ä»1900-2100
- ä¼å代ç é»è¾æåæ§è¡æç
- 该çæ¬åä¸åä½é大æ´æ°
2.0.1 stable
- BugFixï¼å¿è®°æ´æ¹æµè¯ä»£ç 导è´çæ¾ç¤ºé®é¢
2.0.2 stable
- BugFixï¼é¡¶é¨è£ 饰ç©ç»å¶éä½é®é¢
2.1.0
- ä¿®æ¹è£ 饰ç©ç»å¶é»è¾ï¼å¯æ ¹æ®æ¥æå¨åä¸åºåç»å¶ä¸åè£ é¥°ç©
2.2.0
- BugFixï¼æåä¸ä¸ªæ份å½åæ¥ææ æ³æ¾ç¤ºé®é¢
é¢è§å¾
å¦ä½éæå°é¡¹ç®
æ¹å¼ä¸ ç´æ¥ä»maven center compile
compile 'cn.aigestudio.datepicker:DatePicker:2.2.0'
æ¹å¼äº æå¨å¯¼å ¥
æ¥éª¤ä¸
å°DatePickerè¿ä¸ªModuleå¯¼å ¥ä½ çProjectä¸
æ¥éª¤äº
å¨ä½ Projectçsettings.gradleæ件ä¸å¢å å¦ä¸å 容ï¼
include ':DatePicker'
è¿éè¦æ³¨æçæ¯å¨ä¸äºgradleçæ¬ä¸éè¦ä»¥è±æéå·çæ¹å¼è¿½å Moduleï¼
include ':YourMoudle',':DatePicker'
æ·»å åå½åºç°âsycn nowâæ示æ¶ç¹å»åæ¥å³å¯
æ¥éª¤ä¸
å¨ä½ 项ç®çbuild.gradleæ件çdependenciesåºåä¸æ·»å å¦ä¸å 容ï¼
compile project(':DatePicker')
å¦ä½ä½¿ç¨
ç®å使ç¨
ä¸æ¦å°DatePickeréæå°é¡¹ç®åä½ ä¾¿å¯ä»¥åæ®éæ§ä»¶é£æ ·ä½¿ç¨å®ã
å¦æä½ éè¦è·åDatePickeræ¥æéæ©åè¿åçæ°æ®ä½ éè¦ä¸ºDatePicker设置ä¸ä¸ªOnDateSelectedListenerçå¬å¨ï¼
......
DatePicker picker = (DatePicker) findViewById(R.id.main_dp);
picker.setDate(2015, 7);
picker.setOnDateSelectedListener(new DatePicker.OnDateSelectedListener() {
@Override
public void onDateSelected(List<String> date) {
String result = "";
Iterator iterator = date.iterator();
while (iterator.hasNext()) {
result += iterator.next();
if (iterator.hasNext()) {
result += "\n";
}
}
Toast.makeText(MainActivity.this, result, Toast.LENGTH_LONG).show();
}
});
......
setDateæ¹æ³å è®¸ä½ è®¾ç½®å½åæåæ¾ç¤ºçå¹´æã注æ该æ¹æ³å¿ é¡»è°ç¨ï¼ä¹å°±æ¯è¯´ä½ å¿ é¡»ä¸ºDatePickeræå®ä¸ä¸ªç¡®åå¹´æ
é»è®¤æ åµä¸DatePicker 2.0çéæ©æ¨¡å¼ä¸ºå¤é模å¼ï¼ä½ å¯ä»¥éè¿setModeæ¹æ³æ¥è®¾ç½®DatePickerçéæ©æ¨¡å¼ï¼è¯¥æ¹æ³æ¥åä¸ä¸ªDPModeç±»åçæ举å¼ï¼DatePicker 2.0æ¯æ两ç§éæ©æ¨¡å¼ï¼åéDPMode.SINGLEåå¤éDPMode.MULTIPLEï¼è®¾ç½®æ¹å¼å¦ä¸ï¼
......
DatePicker picker = (DatePicker) findViewById(R.id.main_dp);
picker.setDate(2015, 7);
picker.setMode(DPMode.SINGLE);
......
å¨åé模å¼ä¸ï¼å¦æä½ æ³è¦è·åDatePickeræ¥æéæ©åè¿åçæ°æ®ï¼ä½ å°±ä¸è½åå°DatePickerççå¬è®¾ç½®ä¸ºOnDateSelectedListenerèåºè¯¥è®¾ç½®ä¸ºOnDatePickedListenerï¼
......
DatePicker picker = (DatePicker) findViewById(R.id.main_dp);
picker.setDate(2015, 7);
picker.setMode(DPMode.SINGLE);
picker.setOnDatePickedListener(new DatePicker.OnDatePickedListener() {
@Override
public void onDatePicked(String date) {
Toast.makeText(MainActivity.this, date, Toast.LENGTH_LONG).show();
}
});
......
è¿ééè¦æ³¨æçæ¯ï¼ä½ ä¸è½å°DatePicker设置为å¤éæåé模å¼çæ åµä¸å设置为åéæå¤éï¼å¨ä¸ä¸ªå®ä¾ä¸åªè½æ¥åä¸ç§éæ©æ¨¡å¼
éæ©åçæ¥æå°ä¼ä»¥å表ï¼å¤é模å¼ä¸ï¼æå符串ï¼åé模å¼ä¸ï¼çå½¢å¼è¿åï¼æ¥æå符串çæ ¼å¼ä¸ºï¼
yyyy-M-d
æ¯å¦ï¼2015-3-28
é«çº§å®å¶
DatePicker 2.0é»è®¤äºä¸å¥æ¾ç¤ºæºå¶ï¼å¯¹äºå¤©ææåèè¨ï¼2015å¹´çåæä¸è¡¥ä¼é½ä¼è¢«ä¸åçèæ¯åé¢è²ææ è¯ï¼å¯¹äºå ¶ä»å½å®¶æåèè¨åªæåæä¼è¢«æ è¯ï¼å½ç¶ï¼å¨æäºæ åµä¸ä½ è¿æ³å¨æäºç¹å®çæ¥ææèªå·±çæ¾ç¤ºæ è¯ï¼DatePicker 2.0å¨åæç»å¶å±çåºç¡ä¸åå²åºäºä¸ä¸ªèæ¯å±ï¼æä¾ç»ç¨æ·ç»å¶èªå·±æ³è¦çæ è¯ç©ãæ¯å¦ä½ æ³å¨2015-7-1ï¼2015-7-8ï¼2015-7-16è¿ä¸ä¸ªæ¥æä¸ç»å¶ä¸ä¸ªä¸åçèæ¯åï¼é¦å ä½ è¦éè¿DPCManagerçsetDecorBGæ¹æ³è®¾ç½®ä¸ä¸ªæ¥æå表ï¼è¯¥å表å å«äºéè¦ç»å¶èæ¯æ è¯çæ¥æï¼å¨æ²¡æç¹æ®è¯´æçæ åµä¸ï¼DatePicker 2.0ä¸æ使ç¨å°çæ¥ææ ¼å¼åä¸ä¸è¿°ä¸è´ï¼ï¼
......
List<String> tmp = new ArrayList<>();
tmp.add("2015-7-1");
tmp.add("2015-7-8");
tmp.add("2015-7-16");
DPCManager.getInstance().setDecorBG(tmp);
......
ç¶åä½ å°±å¯ä»¥è°ç¨DatePickerçsetDPDecoræ¹æ³ä¸ºDatePickerç»å¶è£ 饰ç©èæ¯ï¼
......
List<String> tmp = new ArrayList<>();
tmp.add("2015-7-1");
tmp.add("2015-7-8");
tmp.add("2015-7-16");
DPCManager.getInstance().setDecorBG(tmp);
DatePicker picker = (DatePicker) findViewById(R.id.main_dp);
picker.setDate(2015, 7);
picker.setDPDecor(new DPDecor() {
@Override
public void drawDecorBG(Canvas canvas, Rect rect, Paint paint) {
paint.setColor(Color.RED);
canvas.drawCircle(rect.centerX(), rect.centerY(), rect.width() / 2F, paint);
}
});
......
è¿éæ们å¨2015-7-1ï¼2015-7-8ï¼2015-7-16è¿ä¸ä¸ªæ¥æä¸ç»å¶ä¸ä¸ªçº¢è²çèæ¯åï¼
DatePicker 2.0ä¸ææä¾çèæ¯å±ä½äºæ¥æææ¬çä¸æ¹ææå ¶ä»èæ¯çä¸æ¹ï¼ä¹å°±æ¯è¯´å¨ææçèæ¯å±ä¸ï¼ä½ æèªå®ä¹çèæ¯æ¥ææé«å±ç¤ºçä¼å 级
å½ç¶ï¼æäºæ åµä¸å æ¯ç»å¶ä¸ä¸ªèæ¯å±å¾å¾ä¸æ¯ä¸å¤çï¼DatePicker 2.0å åèèå°è¿ä¸ç¹ï¼å¼æ¾äºä½äºåæ¯å±çäºä¸ªè£ 饰åºåç»ç¨æ·ç»å¶ä¸åçè£ é¥°ç©ï¼è¿äºä¸ªè£ 饰åºåçä½ç½®å¤§è´å¦ä¸ï¼
å¦ä¸å¾æ示ï¼DatePicker 2.0å¼æ¾äºä½äºåæ¯å±çAãBãCãDãEäºä¸ªåºå让ç¨äºææºä¼å¨è¿äºåæ¯å±çè¿äºåºåç»å¶ä¸äºè£ 饰ç©ï¼ä½¿ç¨æ¹æ³ä¹é常ç®åï¼ä¸ç»å¶èæ¯è£ 饰ç©çé»è¾ç±»ä¼¼ï¼è¿é以åå«å¨2015-7-5ï¼2015-7-10è¿ä¸¤ä¸ªæ¥æçå·¦ä¸ååä¸è§ç»å¶ä¸åé¢è²å½¢ç¶çå¾å½¢ä¸ºä¾ï¼é¦å ä½ éè¦åç第ä¸æ¥ä¸ç»å¶èæ¯è£ 饰ç©ä¸æ ·ï¼å è°ç¨DPCManagerçç¸å ³æ¹æ³åå§åæ¥ææ°æ®ï¼
......
List<String> tmpTL = new ArrayList<>();
tmpTL.add("2015-7-5");
DPCManager.getInstance().setDecorTL(tmpTL);
List<String> tmpTR = new ArrayList<>();
tmpTR.add("2015-7-10");
DPCManager.getInstance().setDecorTR(tmpTR);
......
è¿éè¡¥å ä¸ç¹ï¼ä»ä¸é¢è£ 饰åºåç示ä¾å¾ä¸å ¶å®å¯ä»¥çå°AãBãCãDãEäºä¸ªåºååå«è¡¨ç¤ºçæ¯å·¦ä¸è§ï¼Top leftï¼ã顶é¨ï¼Topï¼ãå³ä¸è§ï¼Top rightï¼ã左边ï¼Leftï¼ãå³è¾¹ï¼Rightï¼ï¼ä¸ä¹å¯¹åºç设置æ¥ææ°æ®ä¸ç»å¶çæ¹æ³ä¹éç¨ä¸åçå½åæ¥åºåï¼æ¯å¦ä¸é¢ç代ç ä¸æ们为左ä¸è§TLåå³ä¸è§TR设置æ è¯æ¥ææ°æ®å°±åå«ç¨å°äºsetDecorTLæ¹æ³åsetDecorTRæ¹æ³ï¼å½ç¶ï¼å¨ç»å¶çæ¶åæ们ä¹éè¦å¨ç¸åºçæ¹æ³ä¸ç»å¶ï¼
......
List<String> tmpTL = new ArrayList<>();
tmpTL.add("2015-7-5");
DPCManager.getInstance().setDecorTL(tmpTL);
List<String> tmpTR = new ArrayList<>();
tmpTR.add("2015-7-10");
DPCManager.getInstance().setDecorTR(tmpTR);
DatePicker picker = (DatePicker) findViewById(R.id.main_dp);
picker.setDate(2015, 7);
picker.setDPDecor(new DPDecor() {
@Override
public void drawDecorTL(Canvas canvas, Rect rect, Paint paint) {
paint.setColor(Color.GREEN);
canvas.drawRect(rect, paint);
}
@Override
public void drawDecorTR(Canvas canvas, Rect rect, Paint paint) {
paint.setColor(Color.BLUE);
canvas.drawCircle(rect.centerX(), rect.centerY(), rect.width() / 2, paint);
}
});
picker.setOnDateSelectedListener(new DatePicker.OnDateSelectedListener() {
@Override
public void onDateSelected(List<String> date) {
String result = "";
Iterator iterator = date.iterator();
while (iterator.hasNext()) {
result += iterator.next();
if (iterator.hasNext()) {
result += "\n";
}
}
Toast.makeText(MainActivity.this, result, Toast.LENGTH_LONG).show();
}
});
......
ç»å¶ææå¦ä¸ï¼
注æï¼ï¼ï¼è¿éé常éè¦çä¸ç¹æ¯ä½ å¿ é¡»å¨DatePickeræ¾ç¤ºå设置DPCManagerä¸çç¸å ³æ°æ®ï¼ï¼ï¼
åè½æ©å±
DatePicker 2.0æä¾äºä¸ä¸ªManageræ¥ç®¡çæ§ä»¶çå项åè½ï¼å ¶ä¸DPCManagerç¨äºå¯¹æ¥ææ°æ®çå è½½ï¼è¿å¨ä¸é¢çä»ç»ä¸æææåè¿éä¸åå¤è¯´ï¼DPLManagerç¨äºå¯¹è¯è¨ç¯å¢çæ§å¶ï¼DatePicker 2.0å ç½®ä¸æåè±è¯ä¸¤ç§è¯è¨å¹¶ä¼æ ¹æ®å½åç³»ç»çè¯è¨ç¯å¢è¿è¡èªå¨åæ¢ï¼å¦æä½ æ³æ©å±æ´å¤çè¯è¨ï¼åªé继æ¿DPLManager并éåç¸å ³æ¹æ³å³å¯ï¼åæ¶ä½ è¿å¿ é¡»å¨DPLManagerçåä¾æ¹æ³ä¸å¢å ç¸å ³é»è¾ä»¥ä¾¿DatePickerè½è¯å«ä½ çè¯è¨ï¼
/**
* è·åæ¥åè¯è¨ç®¡çå¨
*
* Get DatePicker language manager
*
* @return æ¥åè¯è¨ç®¡çå¨ DatePicker language manager
*/
public static DPLManager getInstance() {
if (null == sLanguage) {
String locale = Locale.getDefault().getLanguage().toLowerCase();
if (locale.equals("zh")) {
sLanguage = new CN();
} else {
sLanguage = new EN();
}
}
return sLanguage;
}
æåæ们è¿æä¾äºä¸ä¸ªDPTManagerç¨äºå¯¹DatePickeræ´ä½è²è°çæ§å¶ï¼å¦æä½ æ³å®ç°èªå·±ç主é¢è²è°ï¼åªé继æ¿DPTheme并å®ç°ç¸å ³æ¹æ³ï¼ç¶ååè°ç¨DPTManagerçinitCalendaræ¹æ³ä¼ å ¥ä½ èªå®ä¹çDPTheme对象å³å¯ãè¿éä¸DPCManagerä¸åçæ¯ä¸»é¢çåå§åï¼ä¹å°±æ¯è¯´DPTManagerçinitCalendaræ¹æ³çè°ç¨ï¼å¿ é¡»å¨DatePickeræé åå®æï¼ï¼ï¼è¿ç¹ä¸DPCManagerå¨DatePickeræ¾ç¤ºåè°ç¨ä¸åï¼ï¼ï¼
è¿éå¼å§æ¯è±æææ¡£
DatePicker
A simple date picker for android~~(note:it doesn't work with horizontal view yet,and it has one or two days deviation of solar term)~~
Android API Needs
API 1
API 11
API 1
Version
1.0.0 beta
Doesn't work with horizontal view yet,but vertical right.
1.1.2 release
- Add animation when date picked.
- Bugfix:color does not change when main color set.
1.1.3 release
- You must specify a exactly width like 320dp or match_parent whether portrait or landscape, In most cases the datepicker is use with dialog, and it will match screen in default mode, you can refer to demo to change dialog width.
2.0.0 stable LTS
- API Support to 1, display the animation on API 11 or above.
- Support single and multiple choice
- Add week view
- Support slide up and down to swith years and left and right for months
- Festival text display in two lines
- Change color for material design
- Add specific background color for holidays and deferred holidays when you use China calendar
- Add specific background color for today in calendar
- Support specify current year and month
- Provide five areas in foreground to draw custom decor
- Provide a area in background to draw custom background decor
- Preset chinese and english language display based on current language environment auto swith
- Support custom language extends
- Preset China and America festival display
- Support custom festival extends
- Support custom theme color extends
2.0.1 stable
BugFix:Something display problem
2.0.2 stable
BugFix:The decor of top area can not be display
2.1.0
- Draw different decorate according to date.
2.2.0
- BugFix:Current day in last month can not display.
Preview
How to add to your project
Method A:compile from maven center
compile 'cn.aigestudio.datepicker:DatePicker:2.2.0'
Method B:Help yourself
step 1
import DatePicker lib to your project
step 2
Add something like below in your settings.gradle file of project:
include ':DatePicker'
Note that in some other gradle version you many add module like below:
include ':YourMoudle',':DatePicker'
Click 'sycn now' when it appear after module add.
step 3
Add something like below in your build.gradle file of project:
compile project(':DatePicker')
Usage
Simple use
Once you add DatePicker to your project you can use it like other views which android define.
You need to set a OnDateSelectedListener callback if you want to obtain dates when dates picked.
DatePicker picker = (DatePicker) findViewById(R.id.main_dp);
picker.setDate(2015, 7);
picker.setOnDateSelectedListener(new DatePicker.OnDateSelectedListener() {
@Override
public void onDateSelected(List<String> date) {
String result = "";
Iterator iterator = date.iterator();
while (iterator.hasNext()) {
result += iterator.next();
if (iterator.hasNext()) {
result += "\n";
}
}
Toast.makeText(MainActivity.this, result, Toast.LENGTH_LONG).show();
}
});
setDate method to set year and month current display.note: setDate method must be call, that's mean you must set a exactly year and month for DatePicker.
By default the select mode of DatePicker 2.0 is multiple, you can call method setMode to change the select mode, it accept a enum value type of DPMode:
......
DatePicker picker = (DatePicker) findViewById(R.id.main_dp);
picker.setDate(2015, 7);
picker.setMode(DPMode.SINGLE);
......
if you want to obtain date when date picked, you can not set the OnDateSelectedListener like below, you have to set the OnDatePickedListener:
......
DatePicker picker = (DatePicker) findViewById(R.id.main_dp);
picker.setDate(2015, 7);
picker.setMode(DPMode.SINGLE);
picker.setOnDatePickedListener(new DatePicker.OnDatePickedListener() {
@Override
public void onDatePicked(String date) {
Toast.makeText(MainActivity.this, date, Toast.LENGTH_LONG).show();
}
});
......
Pay attention to this, you can not set the select mode both single and multiple.
The dates you picker will return in the form of string list(In multiple select) or string(In single select),format of string like below:
yyyy-M-d
For example:2015-3-28
Advanced customization
DatePicker 2.0 has a default display mechanism, there are different color of background circle to mark date of holidays and deferred holidays when you use china calendar, for other countries, only holidays will be marked, But in some cases, you may want to draw your mark of specific dates, DatePicker 2.0 provided a backgroung layer to user to draw your own background. For example, you may want to draw different color circle on 2015-7-1 2015-7-8 and 2015-7-16, the first thing you need to do is call the setDecorBG of DPCManager to set these dates:
......
List<String> tmp = new ArrayList<>();
tmp.add("2015-7-1");
tmp.add("2015-7-8");
tmp.add("2015-7-16");
DPCManager.getInstance().setDecorBG(tmp);
......
And then you can draw the different background through setDPDecor method of DatePicker:
......
List<String> tmp = new ArrayList<>();
tmp.add("2015-7-1");
tmp.add("2015-7-8");
tmp.add("2015-7-16");
DPCManager.getInstance().setDecorBG(tmp);
DatePicker picker = (DatePicker) findViewById(R.id.main_dp);
picker.setDate(2015, 7);
picker.setDPDecor(new DPDecor() {
@Override
public void drawDecorBG(Canvas canvas, Rect rect, Paint paint) {
paint.setColor(Color.RED);
canvas.drawCircle(rect.centerX(), rect.centerY(), rect.width() / 2F, paint);
}
});
......
In this case, we draw a red circle background to mark date 2015-7-1 2015-7-8 2015-7-16:
The custom background layer DatePicker 2.0 provided is below text layer and above all other background layer.
Of course you may want to draw something on foreground, DatePicker 2.0 provide five areas of a foreground layer like below:
You can draw differen graph on these area if you want. The draw logic of this like draw background. For example, we draw a rectangle on the top left of date 2015-7-5 and draw a circle on th top right of date 2015-7-10:
......
List<String> tmpTL = new ArrayList<>();
tmpTL.add("2015-7-5");
DPCManager.getInstance().setDecorTL(tmpTL);
List<String> tmpTR = new ArrayList<>();
tmpTR.add("2015-7-10");
DPCManager.getInstance().setDecorTR(tmpTR);
......
And then call the setDPDecor method of DatePicker and overwrite corresponding method:
......
List<String> tmpTL = new ArrayList<>();
tmpTL.add("2015-7-5");
DPCManager.getInstance().setDecorTL(tmpTL);
List<String> tmpTR = new ArrayList<>();
tmpTR.add("2015-7-10");
DPCManager.getInstance().setDecorTR(tmpTR);
DatePicker picker = (DatePicker) findViewById(R.id.main_dp);
picker.setDate(2015, 7);
picker.setDPDecor(new DPDecor() {
@Override
public void drawDecorTL(Canvas canvas, Rect rect, Paint paint) {
paint.setColor(Color.GREEN);
canvas.drawRect(rect, paint);
}
@Override
public void drawDecorTR(Canvas canvas, Rect rect, Paint paint) {
paint.setColor(Color.BLUE);
canvas.drawCircle(rect.centerX(), rect.centerY(), rect.width() / 2, paint);
}
});
picker.setOnDateSelectedListener(new DatePicker.OnDateSelectedListener() {
@Override
public void onDateSelected(List<String> date) {
String result = "";
Iterator iterator = date.iterator();
while (iterator.hasNext()) {
result += iterator.next();
if (iterator.hasNext()) {
result += "\n";
}
}
Toast.makeText(MainActivity.this, result, Toast.LENGTH_LONG).show();
}
});
......
Function expansion
DatePicker 2.0 provide three manager to manage differen function, we use DPCManager to manage date and calendar; Use DPLManager to manage language; Use DPTManager to manage theme color, all of these manager support custom, you can find the usage in notes.
LICENSE
Copyright 2014-2015 AigeStudio(https://github.com/AigeStudio)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
Top Related Projects
lightweight, powerful javascript datetimepicker with no dependencies
A refreshing JavaScript Datepicker — lightweight, no dependencies, modular CSS
A datepicker for twitter bootstrap (@twbs)
JavaScript Date Range, Date and Time Picker Component
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot