4 Star 15 Fork 2

阿债 / datetime.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

datetime.js

Date对象的补充函数,包括类似Python中的strftime()

示例
https://runjs.cn/code/pbphsxrs (已失效) http://jsrun.pro/FafKp/edit

<script>
//在页面导入 datetime.min.js
var format = "%Y年 %B %e日 星期%A %H:%M";
document.write((new Date).strftime(format, "zh"));
document.write("<br>");
document.write((new Date).daysAgo(3).humanize("zh"));
document.write("<br>");
</script>

压缩JS文件

#安装 UglifyJS2
npm install uglify-js -g
#压缩文件
uglifyjs -c -m -o datetime.min.js -- src/datetime.js

Date.prototype.humanize(local)

将最近几天日期改为 今天、昨天、x天前、明天、x天后(x为2~9)

Date.prototype.strftime(format, local)

  • %% 原始的%
  • %Y 4位年份,前置补0
  • %G 4位年份
  • %y 2位年份,前置补0
  • %C 年份前2位(世纪减1),前置补0
  • %m 月份,前置补0
  • %n 月份(Python中无此参数)
  • %B 月份,英文全称
  • %b 月份,英文缩写
  • %d 日期,前置补0
  • %e 日期
  • %j 今年第多少天
  • %U 今年第多少周,周日作为一周开始
  • %W 今年第多少周,周一作为一周开始
  • %w 周几,周日为0
  • %u 周几,周日为7
  • %A 周几,英文全称
  • %a 周几,英文缩写
  • %H 24小时格式时钟,前置补0
  • %k 24小时格式时钟
  • %I 12小时格式时钟,前置补0
  • %l 12小时格式时钟
  • %M 分钟,前置补0
  • %S 秒钟,前置补0
  • %s 时间戳
  • %f 百万分之一秒,前置补0
  • %P 上午或下午,小写带点号(Python中无点号)
  • %p 上午或下午,大写不带点号
  • %z 时区,格式+0800
  • %F 相当于 %Y-%m-%d
  • %D 相当于 %m/%d/%y
  • %x 相当于 %m/%d/%y
  • %T 相当于 %H:%M:%S
  • %X 相当于 %H:%M:%S
  • %R 相当于 %H:%M
  • %r 相当于 %H:%M:%S %p
  • %c 相当于 %a %b %e %H:%M:%S %Y

Date.prototype.getDaysOfYear()

今年第多少天

Date.prototype.getWeeksOfYear(start)

今年第多少周

Date.today()

今天零点的时间戳

Date.prototype.toNow()

回到当前时刻

Date.prototype.toMidnight()

回到午夜零点

Date.prototype.secsAgo(secs)

获取若干秒前

Date.prototype.daysAgo(days)

获取几天前

Date.prototype.monthBegin(offset)

获取月初第一天

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

简介

Date对象的补充函数,包括类似Python中的strftime()。 示例-> 展开 收起
JavaScript 等 2 种语言
MIT
取消

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/azhai/datetime.js.git
git@gitee.com:azhai/datetime.js.git
azhai
datetime.js
datetime.js
master

搜索帮助