[英]Convert date in YYYY/MM/DD format in MomentJS
I am using MomentJS for converting the date format. 我正在使用MomentJS转换日期格式。
I have a date in this format 2010/12/01 and I want to convert it to 01/12/2010 using MomentJS only. 我有这个格式2010/12/01的日期,我想仅使用MomentJS将其转换为01/12/2010。
I have another date in this format "12/02/2014" and I want to convert in "2014/12/02" 我有另一个日期,格式为“12/02/2014”,我想转换为“2014/12/02”
<!--begin snippet: js hide: false console: true babel: false-->
<!--language: lang-js-->
var date = moment(new Date(2010/12/01)).format("MMM Do h/mm");
console.log(date);
<!--language: lang-html-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.min.js"></script>
<!--end snippet-->
How do I convert them using MomentJS 如何使用MomentJS转换它们
你可以试试这个:
moment('2010/12/01', 'YYYY/MM/DD').format('DD/MM/YYYY')
您根本不需要日期库:
'2010/12/01'.split('/').reverse().join('/')
sudoCode sudoCode
moment('date-to-be-converted','format-of-date-to-be-converted').format('desired-format');
moment('12/02/2014','MM/DD/YYYY').format('YYYY/MM/DD');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.