简体   繁体   English

如何生成信用卡/借记卡到期日格式的日期?

[英]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);

With Moment you can simply do:使用Moment ,您可以简单地执行以下操作:

 const date = moment().format("ddd DD/MM"); console.log("Valid until: " + date);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM