Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个场景,我必须为事件设置日期,日期选择器应根据国家或地区采用本地化格式的日期格式。我怎样才能在 AngularJS 中做到这一点?我尝试了很多解决方案,但没有找到合适的解决方案。
您可以使用 toLocaleDateString()
参考
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
var today = new Date(); var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0)); console.log(date.toLocaleDateString('en-US')); console.log(today.toLocaleDateString('en-US'));