John’s gospel suggests Jesus’ ministry included four Passovers (see The Times, chapter 9), with the last of them being the Passover when Jesus was killed. The synoptic gospels place John the Baptist’s death just before the feeding of the 5000 and John’s gospel places that event around the time of the third Passover in Jesus’ ministry (John 6:4). So that would make it almost exactly one year before Jesus died.
We know that at the time of the first Passover in Jesus’ ministry, John the Baptist had not yet been imprisoned (John 3:24). So he was in prison for less than two years. It was probably not much less than two years, because the next event recorded in John’s gospel is Jesus returning to Galilee (John 4:3) which Matthew says was prompted by John’s imprisonment (Matthew 4:12). So there is good evidence that John was in prison for nearly two years — beginning just after the first Passover in Jesus ministry and ending a year before Jesus died.