My question is, after the 18th month, treatment $B$ also came to the subjects in the treated group. How can the effect of treatment $B$ be identified?
According to my reading of your question, the same subjects received two exposures with adjacent post-periods. Further, it is my understanding that they represent entirely different treatments, though you did not explicitly say what $A$ and $B$ represent in your study. The onset of the first exposure is in the sixth month; this treatment hits all subjects in the treatment group at the same time. Immediately before the onset of the second exposure, the first is withdrawn. Thus, the treatment group is, technically, in a perpetually treated condition—though subjects receive two different types of treatment over time. Since each "after" period is well-defined, then you can actually write this as the interaction of a treatment dummy with two post-treatment indicators. The classical equation with two treatment regimes is as follows:
$$
y_{it} = \gamma T_i + \lambda A_{1t} + \lambda A_{2t} + \delta_1 (T_i \times A_{1t}) + \delta_2 (T_i \times A_{2t}) + \alpha X_{it} + u_{it},
$$
where $T_i$ is equal unity for treated subjects, 0 otherwise. $A_{1t}$ turns in months 6–18, 0 otherwise. $A_{1t}$ turns in months 19–24, 0 otherwise. To simplify this approach, create one column with the three epochs appropriately labeled. Multiply your treatment dummy with a 'factorized' version of this and you got yourself a separate estimate for each post-period.
In settings with multiple treatments, I am partial to dummy variable notation. The following is the more general difference-in-differences estimator:
$$
y_{it} = \delta_1 D^{1}_{it} + \delta_2 D^{2}_{it} + \alpha X_{it} + \gamma_i + \lambda_t + u_{it},
$$
where $D^{1}_{it} = T_i \times A_{1t}$ and $D^{2}_{it} = T_i \times A_{2t}$. Note we instantiate each interaction term—manually. The parameters $\gamma_i$ and $\lambda_t$ denote fixed effects for subjects and months, respectively.
The problem here is the adjacency of treatments $A$ and $B$. Note how the removal of treatment $A$ and the institution of treatment $B$ is immediate. The variable $D^{2}_{it}$ is estimating a second treatment effect. How will you disentangle the effects of $A$ and $B$? Note how we have three epochs, which results in two contrasts. The pre- versus post-period for treatment $A$ and the pre versus post-period for treatment $B$. The periods before the sixth month serve as the pre-period for the second intervention. Note, it is permissible to use the second epoch (i.e., months 6–18) as the pre-period (i.e., reference epoch) for treatment $B$. Is just matters how we code our post-treatment variable. But treatment $A$ may have offset parallel trends before the onset of treatment $B$, which will bias your estimate of $\delta_2$. Again, this assumes you want to a clean estimate for treatment $B$.
This equation is useful if you wanted to track the effects of one intervention as it switches 'on' and 'off' over time. In your setting, the same subjects experience sequential treatments. Are you concerned about any strong lingering effects after treatment $A$ is removed? Suppose treated subjects experience a reduction in average outcomes following treatment $B$ relative to control subjects. Is this the actual effect of treatment $B$, or is it simply subjects rebounding from their previous treatment? This is something you should consider.
Since market conditions did in fact change following the introduction of treatment $A$, then the first treatment is actually a time-varying confounder. We could adjust for a previous intervention, but you'd be assuming the periods before the sixth month serve as a counterfactual for later treatments (i.e., treatment $B$). Matching on pre-intervention outcomes is a safe choice. Maybe a subset of subjects were more likely to be eligible for the second intervention, rather than both. In the end, you want two distinct treatment groups: one eligible for $A$ and a second eligible for $B$.