Example

示例

import React, { Component } from 'react';
import {View,StyleSheet,DatePickerAndroid ,Dimensions} from 'react-native';
const {height,width}=Dimensions.get('window');
export class pageComponent extends Component {
    constructor(props){
        super(props);
    }
    async componentDidMount() {
        try {
            const {action, year, month, day} = await DatePickerAndroid.open({
                // 要设置默认值为今天的话,使用`new Date()`即可。
                // 下面显示的会是2020年5月25日。月份是从0开始算的。
                date: new Date(2020, 2, 6)
            });
            if (action !== DatePickerAndroid.dismissedAction) {
                alert(year+'年'+month+'月'+day+'日')
                // 这里开始可以处理用户选好的年月日三个参数:year, month (0-11), day
            }
        } catch ({code, message}) {
            console.warn('Cannot open date picker', message);
        }
    }

    render(){
        return(
            <View style={styles.container}>

            </View>
        )
    }
}
const styles = StyleSheet.create({
    container: {
        flex:1,
        alignItems: 'center',
        justifyContent:'center'
    },
});
该文件修订时间: 2021-01-14 15:02:10

results matching ""

    No results matching ""