在我的 React 應用程序中,我嘗試在<p>...</p>標簽內格式化日期字符串,如下所示:<p> {new Intl.DateTimeFormat("en-US", { year: "numeric", month: "short", day: "2-digit" }).format(string)}</p>的一個例子string是"2012-10-16T17:57:28.556094Z"。這產生了RangeError: Invalid time value。但是,通過轉換String為Date,下面的代碼起作用了。<p> {new Intl.DateTimeFormat("en-US", { year: "numeric", month: "short", day: "2-digit" }).format(new Date(string))}</p>不應該Intl.DateTimeFormat能夠String正確解析?
Intl.DateTimeFormat 無法解析有效的時間值
MMTTMM
2023-04-27 15:18:12