diff --git a/src/index.js b/src/index.js
--- a/src/index.js
+++ b/src/index.js
@@ -280,7 +280,7 @@ class Dayjs {
 
     const matches = {
       YY: String(this.$y).slice(-2),
-      YYYY: this.$y,
+      YYYY: Utils.s(this.$y, 4, '0'),
       M: $M + 1,
       MM: Utils.s($M + 1, 2, '0'),
       MMM: getShort(locale.monthsShort, $M, months, 3),

diff --git a/test/display.test.js b/test/display.test.js
--- a/test/display.test.js
+++ b/test/display.test.js
@@ -260,3 +260,15 @@ it('As JSON -> toJSON', () => {
 it('As ISO 8601 String -> toISOString e.g. 2013-02-04T22:44:30.652Z', () => {
   expect(dayjs().toISOString()).toBe(moment().toISOString())
 })
+
+it('Year 1 formatted with YYYY should pad with zeroes', () => {
+  const date = new Date(1, 0, 1)
+  date.setUTCFullYear(1) // Required because 0-99 are parsed as 19xx in JS: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#year
+  expect(dayjs(date).format('YYYY')).toBe('0001')
+})
+
+it('Year 1 formatting matches moment format', () => {
+  const date = new Date(1, 0, 1)
+  date.setUTCFullYear(1)
+  expect(dayjs(date).format('YYYY')).toBe(moment(date).format('YYYY'))
+})

'YYYY' results in missing leading zeroes when year <1000
**Describe the bug**
If the year component of a date is less than 1000, the leading zeroes are omitted when trying to format the year with `'YYYY'`.

E.g.:

```js
dayjs(Date.parse('0001-01-01')).format('YYYY-MM-DD') //=> '1-01-01'
dayjs(Date.parse('0010-01-01')).format('YYYY-MM-DD') //=> '10-01-01'
dayjs(Date.parse('0100-01-01')).format('YYYY-MM-DD') //=> '100-01-01'
```

**Expected behavior**
`'YYYY'` in the format string should place leading zeroes to make sure the year takes up 4 digits in the output.

E.g.:

```js
dayjs(Date.parse('0001-01-01')).format('YYYY-MM-DD') //=> '0001-01-01'
dayjs(Date.parse('0010-01-01')).format('YYYY-MM-DD') //=> '0010-01-01'
dayjs(Date.parse('0100-01-01')).format('YYYY-MM-DD') //=> '0100-01-01'
```

**Information**
 - Day.js Version: v1.11.7
 - OS: Windows 11
 - Browser Firefox, NodeJS console
 - Time zone: CET (UTC +1), Central European Time (Europe/Stockholm) (DST not in effect)


test/timezone.test.js(1) test/timezone.test.js(2) test/timezone.test.js(3) test/timezone.test.js(4)
test/display.test.js