How does a capacitor get charged instantly in AC whereas it takes infinite time in DC? I have seen when a capacitor is connected to a dc source it takes infinte time to charge, but when connected to ac it takes the potential of the source instantly,
probably the approach in the books is not adequate, please clarify,
Here is a link that mentions the time constant for DC https://www.electronics-tutorials.ws/accircuits/ac-capacitance.html
And here is one that describes the AC https://physicscatalyst.com/elecmagnetism/growth-and-delay-charge-R-C-circuit.php
 A: Regarding the transient currents (transient regime actually), it is there when you turn on an AC circuit that was off.  I mean when you switch on the power. What you see in most description is the solution after the transients have "died" but the complete solution includes both.  In most introductory physics we don't see this mentioned but electrical engineering books should have it. If you had AC circuit with very large inductance you could actually see the delay until the non-transient regime takes over.
A: Capacitors always take time to charge. In practice, when a capacitors is ~99%  charged , we can call it fully charged. The exponential which is used to describe the charging of a capacitors does not make sense when time is very large because charge can never be less than charge of an electron while in the exponential equation, for a large enough time you can get charge less than charge of an electron which is meaningless.
Having that said, the exponential is a very good approximation for short time. In AC (just like DC) the capacitors need some time to charge. It is this extra time that causes the voltage across them to lag behind.
A: The site that you mention says

When a capacitor is connected across a DC supply voltage it charges up to the value of the applied voltage at a rate determined by its time constant.

However the time constant is $\tau = RC$ so it is not a property of the capacitor by itself, but rather the circuit.
Their example circuit for the AC case has a resistance of 0. So the time constant is $\tau=0$. Therefore it will instantaneously charge for both the AC and the DC cases.
