Power Outage Timer

CrossRoads:
Or, get a battery powered clock and a normally closed relay. When power is on, the relay is held in the open position, when power is lost the relay reverts to the normally closed position and the clock runs for as long as the battery holds out, or until power comes back. Don't know how you'd tell when more than 12 or 24 hours had gone by, guess that would depend on the clock used.

That gets me thinking - just to start out, what's the mechanism (parts and accompanying code) for detecting what power source the Arduino is using? Say, for example, a basic sketch that lights a multi-color LED in pin 13 green when using power through the USB jack and red LED if using power from the 9V battery?