如何在矩/日期中格式化至mm/dd/yyyy?
在这里,我将最后一个更新的数据作为这样的API响应,
let data = {
"year": 2021,
"monthValue": 11,
"dayOfMonth": 9
}
我必须将上述对象掩盖此格式mm/dd/yyyy
。
可以使用字符串插值(例如$ {data.data.dayofmonth}/$ {data.monthvalue}/$ {data.year}
,可以使用字符串插值转换上述数据工作完成。
例如,在上面的字符串插值方法中,无法在dayofmonth
和monthvalue
时添加0
单位数字。
我们可以使用MONS
或date-fns
来实现这一目标吗?
Here I am receiving the last updated data as an API response like this
let data = {
"year": 2021,
"monthValue": 11,
"dayOfMonth": 9
}
I have to covert this above object into this format MM/DD/YYYY
.
Can convert the above data using string interpolation like this ${data.dayOfMonth}/${data.monthValue}/${data.year}
But is there any other way we can use libraries to get this work done.
For e.g in the above string interpolation method, can't able to add 0
at the beginning of the dayOfMonth
and monthValue
when they are given as single digits.
can we achieve this using moment
or date-fns
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要库即可零 - pad 1-2位数字:
You don't need a library just to zero-pad a 1–2 digit number: