A two-phase neural network solves exact feasible solutions when the problem is a constrained optimization programming. The time-varying programmming neural network is a kind of modified steepest-gradient algorithm which solves time-varying optimization problems. In this paper, a time-varying two-phase optimization neural network is proposed which uses the merits of the two-phase neural network and the time-varying neural network. The training of multi-layer neural networks is regarded as a time-varying optimization problem, and the proposed algorithm is applied to system identification or function learning and control using a multi-layer neural network. Furthermore, we considered the case where the weights have some constraints in the learning of the neural network.