js日期库moment
发表于|更新于
|浏览量:
健全的身体比金子还珍贵,强壮的体魄比享用不尽的财富还有价值。——佚名
https://github.com/moment/moment
用于解析、验证、操作和格式化日期的 JavaScript 日期库。
文档:
使用非常简单
1 | npm install moment |
1 | var moment = require('moment'); // require |
或者
1 | import moment from 'moment'; |
解析时间
1 | var day = moment("1995-12-25"); |
格式化时间:
1 | moment("12-25-1995", "MM-DD-YYYY"); |
相关推荐
2021-12-01
nvue中tap事件取消冒泡
青春是一种持续的陶醉,是理智的狂热。——拉罗什富科 nvue中@tap.stop阻止冒泡失效了 代码如下: 1<view @tap="parentEvent"><view @tap.stop="childEvent">触发触发</view></view> 大概有两种方案,第一种是改事件,改为@touchend事件 1<view @tap="parentEvent"><view @touchend="childEvent">触发触发</view></view> 不过还有另一种方式 1234567parentEvent(e) { console.log('parentEvent');},childEvent(e) { console.log('childEvent'); e.stopPropagation();}
2021-11-13
箭头函数与this指向探究
我有明珠一颗,久被尘劳关锁,一朝尘净光生,照破山河万朵。——柴陵郁禅师 今天研究了下箭头函数与this,发现了一些挺好玩的特性 首先,我们在控制台输入上这段js 123456789101112131415161718192021var handler = { name :'handler', init: function() { let init1 = function(event) { console.log("init1: ", this); let init5 = function(){ console.log("init5: ", this); } init5(); // init5: Window {window: Window, self: Window, document: document, name: '', loca...
2024-05-17
处理js的JSON.parse中Number太长导致精度丢失问题
大自然的真实和单纯,常是重要艺术极点的基础。——恩格斯 代码如下: 1"token".split(".").slice(0,2).map(i=>JSON.parse(atob(i))) 这里主要是 JSON.parse 导致的,我简单复现一下 1JSON.parse('{"id":9052710354240385291}') 得到的是 1{id: 9052710354240385000} 可以看到后面的 291 变为 000 了 解决方式这里使用正则匹配 /:\s*([-+]?\d+(\.\d+)?([eE][-+]?\d+)?)/g 例如: 123456JSON.parse('{"id":9052710354240385291}'.replace(/:\s*([-+]?\d+(\.\d+)?([eE][-+]?\d+)?)/g, (match, p1) => { ...
2024-07-30
Apache ShenYu实现验证失败后才出来验证码
秋天的风都是从往年吹来的。——木心《素履之往》 今天实现了一个功能 [Improve] need verify code when password error by VampireAchao · Pull Request #465 · apache/shenyu-dashboard · GitHub 也很简单,新增一个state,然后在redux-saga的dispatch触发对应的effects,新增一个callback参数传入过去,然后在请求完成后执行
2023-11-10
minio预签名上传前端axios注意事项
不论替人家做了多少好事,不论多么忠心耿耿,看起来,绝不能指望人家感谢你。——托尔斯泰 之前说过了camel+minio实现预签名URL上传 但当时提供的也是后端代码,现在需要前端axios的 axios文档:Axios API | Axios Docs 123456789101112axios({ method: 'PUT', url, headers: { "Content-Type": "application/octet-stream", }, data: new Blob([file]), responseType: "blob"}).then((res) => { console.log({ res })}).catch(console.error) 这里的file就是前端的File对象,我们此处是将其转换为Blob,然后再通过data参数发送,...
2021-08-30
颜色拾取器
志向是天才的幼苗,经过热爱劳动的双手培育,在肥田沃土里将成长为粗壮的大树。——苏霍姆林斯基 官网:https://www.eyecon.ro/colorpicker/ 效果: 代码: 1234567891011121314151617181920212223242526272829303132<head> <link media="screen" rel="stylesheet" href="admin/plugins/colorpicker/css/colorpicker.css" type="text/css"/></head><body><div> <div id="tag-color-picker"> <input type="text" id="tag-color-input')"/> </div...
