# openharmony-date **Repository Path**: harmonyos4me/openharmony-date ## Basic Information - **Project Name**: openharmony-date - **Description**: 为OpenHarmony开发者提供一个轻量级日期时间戳格式化模块,通过YmdHis随意组合转换。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2025-04-14 - **Last Updated**: 2025-04-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 🔥🔥🔥官方推荐 🎉 # @open/date ## 📚 Introduction Date,轻量级日期时间戳格式化模块,通过YmdHis随意组合转换,使其可以运行在 OpenHarmony,并沿用其现有用法和特性。 ## 🔽 Installation ``` ohpm install @open/date ``` ## ✨ Usage ```js import date from '@open/date' ``` ### date.format | param | desc | |-------|------| | Y | 年 | | m | 月 | | d | 日 | | H | 时 | | i | 分 | | s | 秒 | date.format('随意组合', [时间戳]) ```js date.format('Y-m-d H:i:s'); // 返回当前日期 2024-07-15 22:20:18 date.format('Y/m/d H:i:s'); // 返回当前日期 2024/07/15 22:20:18 date.format('Y/m/d'); // 返回当前日期 2024/07/15 date.format('YmdHis') // 返回当前日期 20240715222018 date.format('Y年m月d日 H:i:s') // 返回当前日期 2024年07月15日 22:20:18 date.format('Y') // 返回当前日期 2024 date.format('m') date.format('d') date.format('H') date.format('i') date.format('s') date.format('Y/m/d H:i:s', 时间戳) // 返回指定日期 date.format('Y/m/d', 时间戳) // 返回指定日期 date.format('Y', 时间戳) // 返回指定日期 date.format('s', 时间戳) // 返回指定日期 ``` ### date.timeAgo 几分钟前、几小时前、几天前等时间差显示效果的代码实例... ```js date.timeAgo(new Date('2022-1-1')) // 3年前 date.timeAgo('2024-5-1') // 8月前 date.timeAgo(Date.now()) // 刚刚 ``` # 💐 How to Contribute 使用过程中发现任何问题都可以提 [Issue](https://gitee.com/webopenfather/openharmony-date/issues) 给我们,当然,我们也非常欢迎你给我们发 [PR](https://gitee.com/webopenfather/openharmony-date) 。 ## 🌏 License MIT