Tempo is a type of frequency.
A tempo mark indicates the note value of a beat, and the number of beats that occur per minute (BPM).
Duration (time) is the inverse of frequency.
So you just have to take the inverse of the tempo to find the duration of a beat.
(But, I imagine you will want to measure the duration in seconds rather than in minutes, so you will have to convert the units.)
Simple Example
If the tempo mark is a quarter-note = 120
, this means that the duration per beat will be:
1 / 120 BPM
= 1 minuet / 120 beats [ x 60 seconds / minute ]
= 0.5 seconds / beat
The total duration of a bar of 3/4
(3 beats per bar, each with the value of a quarter-note) will be:
3 beats x 0.5 seconds / beat
= 1.5 seconds
whereas the total duration of a bar of 4/4
will be:
4 beats x 0.5 seconds / beat
= 2 seconds
Compound Example
If the tempo mark is a dotted-quarter-note = 60
, the duration per beat will be:
1 / 60 BPM
= 1 minuet / 60 beats
= 1 seconds / beat
The total duration of a bar of 6/8
(6 pulses per bar, each with the value of an eighth-note, AKA 2 beats per bar, each with the value of a dotted-quarter-note) will be:
2 beats x 1 seconds / beat
= 2 seconds
Sometimes the tempo mark of a compound time signature indicates the note value of a pulse (instead of a beat), and the number of pulses that occur per minute (PPM).
If the tempo mark is an eighth-note = 180
, the duration per pulse will be:
1 / 180 PPM
= 1 minuet / 180 pulses
= (1/3) seconds / pulse
The duration of a bar of 6/8
will be:
6 pulses x 1/3 seconds / pulse
= 2 seconds