英文:
How to transform YYYYDDD to DD-MM-YYYY
问题
有没有moment.js或其他库提供的转换器,可以将以YYYYDDD格式给出的日期转换为现代日期,如DD-MM-YYYY或类似的格式?
英文:
I have a date which is given in YYYYDDD format, where YYYY is the year and DDD the days through the year (001-365).
Does the library from moment.js or any other library has a conversor for this kind of given dates to a modern date, like DD-MM-YYYY or something similar?
答案1
得分: 1
请看文档中的部分:https://momentjscom.readthedocs.io/en/latest/
// 解析格式为 YYYYDD 的字符串
let momentdate = moment('2023050', "YYYYDDD");
// 转换为格式为 DD-MM-YYYY
let datestring = momentdate.format("DD-MM-YYYY");
console.log(datestring);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>
英文:
See the moment-documentation: https://momentjscom.readthedocs.io/en/latest/
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
// Parse string in format YYYYDD
let momentdate = moment('2023050', "YYYYDDD");
// Convert to format DD-MM-YYYY
let datestring = momentdate.format("DD-MM-YYYY");
console.log(datestring);
<!-- language: lang-html -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论