Particle-in-cell simulations were performed to understand the interaction of the solar wind with localized magnetic fields on the sunlit surface of the Moon. The results indicated a mini-magnetosphere was formed which had a thin magnetopause with the thickness of the electron skin depth. It was also found that the solar wind penetrated into the cavity of the magnetosphere intermittently rather than in a steady manner. The solar wind that moved around the magnetosphere was observed to hit the surface of the Moon, implying that it may be the cause of the lunar swirl formation on the surface.