项目作者: HLJuaner

项目描述 :
:briefcase: :coffee: Utils-date is a js toolkit for manipulating Date objects(utils-date 是一个操作 Date 对象的 js 工具包)
高级语言: JavaScript
项目地址: git://github.com/HLJuaner/utils-date.git
创建时间: 2018-07-24T02:52:40Z
项目社区:https://github.com/HLJuaner/utils-date

开源协议:MIT License

下载


git fork " class="reference-link">Utils Date git start git fork

releases version
node version
npm version
yarn version
rollup version

Utils Date is a toolkit for extending JavaScript Date objects and is designed to be lightweight, simple, and easy to use.

You can see more details by visiting the Utils Date website.

Install

npm

  1. $ npm install utils-date

yarn

  1. $ yarn install utils-date

Features

  • Conversion date
  • Date format
  • Date calculation

How to use

Used in ES6 or ES6+

  1. import utilsDate form 'utils-date';

Used in Web

  1. <script src="https://unpkg.com/utils-date@1.2.0/dist/utils-date.min.js"></script>
  • Conversion date
  1. // Timestamp conversion
  2. utilsDate.parse(1528278558218); // Wed Jun 06 2018 17:49:18 GMT+0800 (中国标准时间)
  3. // Sql date conversion
  4. utilsDate.parse(/Date(1528278558218)/); // Wed Jun 06 2018 17:49:18 GMT+0800 (中国标准时间)
  5. // UTC time conversion
  6. utilsDate.parse("Wed Jun 06 2018 17:49:18 GMT+0800 (中国标准时间)"); // Thu Jun 07 2018 01:49:18 GMT+0800 (中国标准时间)
  7. // String date conversion
  8. utilsDate.parse("2018"); // Mon Jan 01 2018 08:00:00 GMT+0800 (中国标准时间)
  9. utilsDate.parse("2018-6"); // Fri Jun 01 2018 00:00:00 GMT+0800 (中国标准时间)
  10. utilsDate.parse("2018-6-7"); // Thu Jun 07 2018 00:00:00 GMT+0800 (中国标准时间)
  11. utilsDate.parse("2018-6-7 9"); // Fri Jun 01 2018 07:09:00 GMT+0800 (中国标准时间)
  12. utilsDate.parse("2018-6-7 9:00"); // Fri Jun 01 2018 07:09:00 GMT+0800 (中国标准时间)
  13. utilsDate.parse("2018-6-7 9:00:00"); // Fri Jun 01 2018 07:09:00 GMT+0800 (中国标准时间)
  14. utilsDate.parse("1528278558218"); // Wed Jun 06 2018 17:49:18 GMT+0800 (中国标准时间)
  15. utilsDate.parse("/Date(1528278558218)/"); // Wed Jun 06 2018 17:49:18 GMT+0800 (中国标准时间)
  • Date format
  1. // Used Date extend format 24 hours
  2. new Date().format("yyyy-MM-dd HH:mm:ss 星期 w"); // 2018-07-23 16:40:21 星期 一
  3. new Date().format("yyyy-MM-dd HH:mm:ss"); // 2018-07-23 16:17:21
  4. new Date().format("yy-M-d H:m:s"); // 18-7-23 16:17:21
  5. new Date().format("yy 年 M 月 d 日 H 时 m 分 s 秒"); // 18 年 7 月 23 日 16 时 17 分 21 秒
  6. new Date().format("yyyy-MM-dd"); // 2018-07-23
  7. new Date().format("yy"); // 18
  8. new Date().format("MM"); // 07
  9. new Date().format("M"); // 7
  10. // Used Date extend format 12 hours
  11. new Date().format("yyyy-MM-dd hh:mm:ss"); // 2018-07-23 04:20:43
  12. // Used utils-date
  13. utilsDate.format(new Date(),"yyyy-MM-dd HH:mm:ss"); // 2018-07-23 16:22:42
  14. utilsDate.format(1528278558218,"yyyy-MM-dd HH:mm:ss"); // 2018-06-06 17:49:18
  15. utilsDate.format(/Date(1528278558218)/,"yyyy-MM-dd HH:mm:ss"); // 2018-06-06 17:49:18
  16. utilsDate.format("Wed Jun 06 2018 17:49:18 GMT+0800 (中国标准时间)","yyyy-MM-dd HH:mm:ss"); // 2018-06-07 01:49:18
  17. utilsDate.format("2018","yyyy-MM-dd 00:00:00"); // 2018-01-01 00:00:00
  • Date calculation

    1. // Used Date extend add
    2. new Date().add(1,"year"); // Tue Jul 23 2019 21:59:33 GMT+0800 (中国标准时间)
    3. new Date().add(1,"month"); // Thu Aug 23 2018 22:00:19 GMT+0800 (中国标准时间)
    4. new Date().add(-1,"date"); // Sun Jul 22 2018 22:00:53 GMT+0800 (中国标准时间)
    5. new Date().add(-1,"hour"); // Mon Jul 23 2018 21:01:29 GMT+0800 (中国标准时间)
    6. new Date().add(-1,"minute"); // Mon Jul 23 2018 22:01:05 GMT+0800 (中国标准时间)
    7. new Date().add(-1,"second"); // Mon Jul 23 2018 22:02:33 GMT+0800 (中国标准时间)
    8. new Date().add(-1,"milisecond"); // Mon Jul 23 2018 22:01:33 GMT+0800 (中国标准时间)
    9. // Used Date extend method
    10. new Date().addYear(1); // Tue Jul 23 2019 22:03:24 GMT+0800 (中国标准时间)
    11. new Date().addMonth(1); // Thu Aug 23 2018 22:03:48 GMT+0800 (中国标准时间)
    12. new Date().addDate(-1); // Sun Jul 22 2018 22:04:20 GMT+0800 (中国标准时间)
    13. new Date().addHour(-1); // Mon Jul 23 2018 21:04:48 GMT+0800 (中国标准时间)
    14. new Date().addMinute(1); // Mon Jul 23 2018 22:06:37 GMT+0800 (中国标准时间)
    15. new Date().addSecond(1); // Mon Jul 23 2018 22:02:33 GMT+0800 (中国标准时间)
    16. new Date().addMilisecond(-1); // Mon Jul 23 2018 22:01:33 GMT+0800 (中国标准时间)
    17. // Used utils-date
    18. utilsDate.add(1528278558218,1,"year"); // Tue Jul 23 2019 22:03:24 GMT+0800 (中国标准时间)
    19. utilsDate.add("1528278558218",1,utilsDate.YEAR); // Tue Jul 23 2019 22:03:24 GMT+0800 (中国标准时间)
    20. utilsDate.add(/Date(1528278558218)/, -1 , utilsDate.MONTH); // Sun May 06 2018 17:49:18 GMT+0800 (中国标准时间)
    21. utilsDate.add("Wed Jun 06 2018 17:49:18 GMT+0800 (中国标准时间)", 1 , utilsDate.DATE); // Fri Jun 08 2018 01:49:18 GMT+0800 (中国标准时间)
    22. utilsDate.add("2018", 1 , utilsDate.HOUR); // Mon Jan 01 2018 09:00:00 GMT+0800 (中国标准时间)
    23. utilsDate.add("2018-2-1", 1 , utilsDate.MINUTE); // Mon Jan 01 2018 00:01:00 GMT+0800 (中国标准时间)

MIT

  1. Copyright (c) 2018 Slience HVK
  2. Permission is hereby granted, free of charge, to any person obtaining a copy
  3. of this software and associated documentation files (the "Software"), to deal
  4. in the Software without restriction, including without limitation the rights
  5. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  6. copies of the Software, and to permit persons to whom the Software is
  7. furnished to do so, subject to the following conditions:
  8. The above copyright notice and this permission notice shall be included in all
  9. copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  14. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  15. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  16. SOFTWARE.