The name "Japan" was used in the late 7th century.
Its origin is not clearly recorded in Japanese history books, but China's New Book of the Tang Dynasty records that in the first year of Xianheng in Tang Gaozong (670), the Japanese sent messengers to congratulate the Tang Dynasty on pacifying Koguryo. Because I know a little Chinese, I hate the name "Japan", so I changed the name of the country to Japan, and the envoys claimed that it was named because of its geographical location near sunrise.
Extended data:
The earliest archaeological discovery of the name "Japan" was the Epitaph of Your Army unearthed in Xi 'an, China on 201/,which was written in 678. This shows that the name "Japan" was used no later than the late 7th century. Historically, Japan once had other nicknames such as Daiwa, Japan and Fusang.
The record of the ten years (670) of King Wu Wenwang in the "History of the Three Kingdoms" of North Korea is also consistent with this: "Japan is more famous than Japan, and recently claimed to be famous." Zhang Shoujie of the Tang Dynasty recorded that "Wuhou changed Japan to Japan".
References:
Baidu encyclopedia Japan