Take the following circuit;

Using Kirchhoff’s 2nd law, we can write;

V_{s} = IR + V_{c}

V_{s} - IR - V_{c} = 0         (1)

A charging capacitor has charge deposited onto its plates and as the capacitor gets more charged it becomes increasingly difficult for further charge to build up on it (because of the increasing electrostatic charge). Therefore the current flow decreases over time. Since \Delta Q = I \Delta t , we can write;

I = \frac{dQ}{dt}         (2)

Since, by definition C = \frac{Q}{V} ;

V_{c} = \frac{Q}{C}         (3)

Substituting equations  2  and  3  into  1  gives;

V_{s} - \frac{dQ}{dt}R - \frac{Q}{C} = 0

Rearranging to give \frac{dQ}{dt} ;

-R\frac{dQ}{dt} = \frac{Q}{C} - V_{s}

R\frac{dQ}{dt} = V_{s} - \frac{Q}{C}

\frac{dQ}{dt} = \frac{1}{R}(V_{s} - \frac{Q}{C})

In order to integrate and remove the ‘rate of change of time’, so exact values for charge at a particular time frame can be given;

{dQ} = \frac{1}{R}(V_{s} - \frac{Q}{C})dt

\frac{dQ}{V_{s} - \frac{Q}{C}} = \frac{1}{R}dt

Dividing both sides by  -C gives;

\frac{dQ}{-CV_{s} + Q} = - \frac{1}{CR} dt

Putting the equation into this form tells us to integrate the equation. If the capacitor is to be charged from a start time of 0 s , where it has no charge (Q = 0 ), to another point in time  t where it will contain a charge  Q = q we can write;

\int_{0}^{q} \frac{dQ}{-CV_{s} + Q} = \int_{0}^{t}(- \frac{1}{CR}) dt

This equation becomes;

[ \ln(Q - CV_{s})]_{0}^{q} = [- \frac{t}{RC}]_{0}^{t}

\ln(q - CV_{s}) - \ln(-CV_{s}) = - \frac{t}{RC} - 0

Using log rules whereby  \ln X - \ln Y = \ln \frac{X}{Y} , this becomes;

\ln(\frac{q - CV_{s}}{-CV_{s}}) = - \frac{t}{RC}

Taking the exponential of both sides gives;

e^{ \frac{\ln(q - CV_{s})}{\ln(-CV_{s})}} = e^{- \frac{t}{RC}}

\frac{q - CV_{s}}{ - CV_{s}} = e^{- \frac{t}{RC}}

Rearranging for q gives;

q - CV_{s} = - CV_{s}e^{- \frac{t}{RC}}

q = CV_{s} - CV_{s}e^{- \frac{t}{RC}}

q = CV_{s}(1 - e^{- \frac{t}{RC}})

Dividing by C gives;  \frac{q}{C} = V_{s}(1 - e^{- \frac{t}{RC}})

Since  \frac{q}{C} = V(t)

where, V_{t}  is the p.d. at time  t

V_{t} = V_{s}(1 - e^{- \frac{t}{RC}})

V_{s} is the initial voltage supplied by the cell when the  capacitor had no charge across it.
R is the resistance supplied by the circuit in which the capacitor and cell are part of
C is the capacitance of the capacitor

Thinking back to the original step where;

V_{s} - IR - V_{c} = 0

When charging the capacitor,  Q = 0  and  t = 0

Therefore V_{s} = IR and so I = \frac{V_{s}}{R}

Since I = \frac{dQ}{dt} ,  I(t) = \frac{d}{dt}Q(t)

I(t) = \frac{d}{dt}[CV_{s}(1- e^{( \frac{-t}{CR})})]

I(t) = -{-CV_{s} \frac{1}{CR} e^{( \frac{-t}{CR})}}

I(t) = V_{s} \frac{1}{R}e^{( \frac{-t}{CR})}

I(t) = \frac{ V_{s}}{R}e^{( \frac{-t}{CR})}

Since the current at time  t  can now be written as  \frac{V_{s}}{R} = I_{0} ;

I(t) = I_{0} \ e^{( \frac{-t}{CR})}

I_{0}  is the initial current, at the start of the process of charging the capacitor.