In this paper, the specified-time bearing-based formation control problem is investigated via a dynamic gain approach. Both the leader-follower and leaderless cases for single- and double-integral multi-agent systems are considered with bearing measurement, respectively. By considering the communication graph as bearing rigid, distributed bearing-based controllers with a time-varying gain are designed. By using time transformation method and Lyapunov stability theory, the close-loop systems under the proposed protocols can achieve the target formation within the specified time. Comparing with some existing results, the proposed approaches can make multi-agent systems converge to the desired formation within any preset time without dependence on the initial conditions or system parameters. Finally, some simulations and experiments are presented to demonstrate the effectiveness of the proposed algorithms.