/**? Sample React Native App?
* https://github.com/facebook/react-native?
* @flow? */
"Use Strict"
Import React, {Component} from ' React '
Import {
Appregistry,
View,
Text,
Datepickerios,
StyleSheet
} from ' React-native '
Class HelloWorld extends Component {
Constructor (props) {
Super (props)
Let remindtime = "2018/12/20"//If it is 2018-12-20, the reversal will fail
Let maxdate = new Date (remindtime)
Let tempdate = new Date ()
this.state={
Defaultdate:tempdate,
Maxdate:maxdate,
CurrDateStr:tempDate.toDateString ()
}
}
//Legacy problem: DatePicker cannot choose the time, no matter how the sliding let go, will immediately revert to the current time. I don't know what to do for a moment.
Datepickerchanged (date) {
This.setstate = ({
Defaultdate:date,
CurrDateStr:date.toDateString ()
});
}
Render () {
Return (
<view style={styles.container}>
<text style={styles.text}>{this.state.currdatestr}</text>
<datepickerios
Date={this.state.defaultdate}//Default time
mode={' Date '}//DatePicker style ' date ' (date), ' Time ', ' datetime ' (Date and time)
Minimumdate={new date ()}//Minimum time (the current time is set here)
Maximumdate={this.state.maxdate}
Minuteinterval={1}//Minimum time interval (default 1 minutes, if set 5, then picker on: 00, 05, 10 ...)
ondatechange={(date) = this.datepickerchanged (date)}/>
</View>
);
}
}
Const STYLES = Stylesheet.create ({
Container: {
Flex:1,
Justifycontent: ' Center ',
Alignitems: ' Center ',
BackgroundColor: ' #F5FCFF '
},
Text: {
width:200, huh?
Height:60,
BackgroundColor: ' White ',?
Justifycontent: ' Center ',?
Alignitems: ' Center ',?
Borderradius:5,
},
picker:{
Padding:50
}
})
Appregistry.registercomponent (' HelloWorld ', () = HelloWorld);
Related Knowledge Point ******************************
/*
* 2, access to mydate year
var mydate = new Date ();
Mydate.getyear (); Get Current year (2-bit)
Mydate.getfullyear (); Get the full year (4-bit)
Mydate.getmonth (); Get the current month (0-11, 0 for January)
Mydate.getmonth (+1); Get the correct month
Mydate.getdate (); Get current day (1-31)
Mydate.getday (); Get Current week x (0-6, 0 for Sunday)
Mydate.gettime (); Gets the current time (the number of milliseconds since 1970.1.1)
Mydate.gethours (); Get current number of hours (0-23)
Mydate.getminutes (); Gets the current number of minutes (0-59)
Mydate.getseconds (); Gets the current number of seconds (0-59)
Mydate.getmilliseconds (); Gets the current number of milliseconds (0-999)
Mydate.tolocaledatestring (); Get Current date
var mytime=mydate.tolocaletimestring (); Get current time
Mydate.tolocalestring (); Get Date and time
* */
****************************** ******************************
React Native Datepickerios