var minute = 1000 * 60; var hour = minute *60; var day = hour *24; var week = day * 7; var month = day * 30; function getTimer(stringTime){ var time1 = new Date().getTime();//当前的时间戳 console.log(time1); var time2 = Date.parse(new Date(stringTime));//指
formatMsgTime (timespan) { var dateTime = new Date(timespan); var year = dateTime.getFullYear(); var month = dateTime.getMonth() + 1; var day = dateTime.getDate(); var hour = dateTime.getHours(); var minute = dateTime.getMinutes(); var second = dateT
背景:最近公司要做动态列表,类似于微信朋友圈.动态创建时间就需要显示为 刚刚.几分钟前.几小时前.几天前.2018-05-15,这样的形式. 代码如下 var minute = 1000 * 60; var hour = minute * 60; var day = hour * 24; // 计算时间差 handleDate(minute, hour, day,dateTimeStamp) { var result = ''; var now = new Date().getTime(); v
function getDateDiff(dateTimeStamp){ var minute = 1000 * 60; var hour = minute * 60; var day = hour * 24; var halfamonth = day * 15; var month = day * 30; var now = new Date().getTime(); var diffValue = now - dateTimeStamp; if(diffValue < 0){return;}
最近需要实现题目的功能,因为我的时间戳是PHP生成的,所以转换JS时间戳需要乘1000,废话不多说,看下面的代码把! 大家可以判断一下传进来的值是否为数值型,还有判断是否比当前的时间戳大!可以根据结果提示非法参数等等! function getDateDiff(dateTimeStamp){ var minute = 1000 * 60; var hour = minute * 60; var day = hour * 24; var halfamonth = day * 15; var mon
转换标准时间为时间戳: function getDateTimeStamp(dateStr){ return Date.parse(dateStr.replace(/-/gi,"/")); } 计算时间差: function getDateDiff(dateTimeStamp) { * ; ; ; ; ; ; var now = new Date().getTime(); var diffValue = now - dateTimeStamp; ) { return; } var ye
// 时间戳转多少分钟之前 getDateDiff(dateTimeStamp) { // 时间字符串转时间戳 var timestamp = new Date(dateTimeStamp).getTime(); var minute = 1000 * 60; var hour = minute * 60; var day = hour * 24; var halfamonth = day * 15; var month = day * 30; var year = day * 365; var