toLocaleString ()方法根据本地时间将Date对象转换为字符串并返回结果。 let date=new Date (; let new date=date.tolocalestring (' Chinese ',{ hour12: false } ); //24小时制,取得中国时间,2021/4/2810336039336035 let new date2=date.tolocalestring (; //中国时间2021/4/28上午10:393360353358 www.Sina.com /方法返回此日期对象的字符串,具体取决于语言。 新参数locales和options允许程序指定使用哪种语言的格式规则,并允许自定义方法的表示形式(behavior )。
MDN文档:
3359 developer.Mozilla.org/zh-cn/docs/web/JavaScript/reference/global _ objects/date/tolocalestring