如何获取react-datetime日期?

时间:2019-03-08 23:35:28

标签: javascript reactjs time

我正在使用react-datetime和moment。

如何使用onChange获取更改的日期?并返回字符串

    private func updateNodePosition(){

        if updateNodes{

            locationUpdate += 1

            SCNTransaction.begin()

            SCNTransaction.animationDuration = 1

            if updateLocations.count > 0 {

                myLocation = CLLocation.bestLocationEstimate(locations: 
                updateLocations)

                for node in nodes {

                    print("@7")

                    let translation = Matrix.transformMatrix(for: 

matrix_identity_float4x4, originLocation: myLocation, location: node.location)

                    let position = SCNVector3.positionForNode(transform: 
                    translation)

                    let distance = node.location.distance(from: myLocation)

                    DispatchQueue.main.async {

                        let scale = 100 / Float(distance)

                        node.scale = SCNVector3(x: scale, y: scale, z: scale)

                        node.position = position

                        node.anchor = ARAnchor(transform: translation)

                        print("@8")
                    }
                }
                for pathN in pathNodes {

                    print("@9")

                    let translation = Matrix.transformMatrix(for: 

                    matrix_identity_float4x4, originLocation: myLocation,

                    location: pathN.location)
                    let position = SCNVector3.positionForNode(transform: 
                    translation)

                    let distance = pathN.location.distance(from: myLocation)

                    DispatchQueue.main.async {

                        let scale = 100 / Float(distance)

                        pathN.scale = SCNVector3(x: scale, y: scale, z: scale)

                        pathN.position = position

                        pathN.anchor = ARAnchor(transform: translation)

                        print("@10")
                    }
                    //add vectors to path

                    pathPoints.append(position)
                }
            }
            SCNTransaction.commit()

            path()
        }
        mapView.addOverlay(myRoute.polyline)
    }

1 个答案:

答案 0 :(得分:1)

您必须为onChange创建一个处理程序,如下所示:

handleChange=(value)=>{
   //value is the changed value
  this.setState({date: value})
}

<DateTime 
    defaultValue={this.state.date}
    timeFormat={false}
    onChange={handleChange}
/>

然后值是更改后的值。每次日期时间调用onChange时都会调用句柄更改功能。