The invention discloses a switching power supply controller for constant current driving of an LED by primary side control, a method for the constant current driving of the LED and a switching power supply formed by using the switching power supply controller. The switching power supply controller comprises an oscillator circuit, an input alternating current average value calculating circuit, a conduction time control circuit, a logic control circuit and a driving circuit. The controller controls the constant current driving of the LED by using a primary side control method to realize same output current and high power factor under the condition with controlled silicon dimming and high-low voltage input; and transformer isolation is directly used, so that the safety performance of the circuits is improved, a peripheral circuit is simple, the circuit cost is reduced, and the PCB (printed circuit board) distribution space is very small in favor of product miniaturization.