[英]How to generate date in the format of credit/debit card expiry date?
I have a requirement of generating dates in this format 'Thru: 12/20'
(like credit/debit card expiry date format).我需要以这种格式生成日期'Thru: 12/20'
(如信用卡/借记卡到期日期格式)。 What is the best way of generating date in this format?以这种格式生成日期的最佳方法是什么?
new Date().toJSON().slice(0,7).split('-').reverse().join('/')
I got the date in mm/yyyy format but couldn't get the desired result我得到了 mm/yyyy 格式的日期,但无法得到想要的结果
You can use Intl.DateTimeFormat
to generate date in day name and dd/MM format您可以使用Intl.DateTimeFormat
以日期名称和 dd/MM 格式生成日期
const options = { weekday: 'short', month: 'numeric', day: 'numeric' }; const result = new Intl.DateTimeFormat('en-GB', options).format(new Date()); console.log(result);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.