How does Bitcoin figure out what time it is? Bitcoin needs to know the current time in order to validate blocks. How does it decide that?

Note that I'm talking about the Satoshi client specifically.
It takes the median time of the other clients connected, but only
 1. if there are at least 5, and
 2. if the median time does not differ from system time by more than 70 minutes.

For specifics, we look at AddTimeData, in timedata.cpp.

Note: I have edited it down for length

void AddTimeData(const CNetAddr&amp; ip, int64 nTime)
{
    int64 nOffsetSample = nTime - GetTime();
    // Add data
    vTimeOffsets.input(nOffsetSample);
    if (vTimeOffsets.size() &gt;= 5 &amp;&amp; vTimeOffsets.size() % 2 == 1)
    {
        int64 nMedian = vTimeOffsets.median();
        // Only let other nodes change our time by so much
        if (abs64(nMedian) &lt; 70 * 60)
        {
            nTimeOffset = nMedian;
        }
        else
        {
            nTimeOffset = 0;
        }
    }
}