// 获取当前时间戳(以s为单位) var timestamp = Date.parse(new Date()); timestamp = timestamp / 1000; //当前时间戳为:1403149534 console.log("当前时间戳为:" + timestamp); // 获取某个时间格式的时间戳 var stringTime = "2014-07-10 10:21:12"; var timestamp2 = Date.parse(new Date(stringTime)); timestamp2 = timestamp2 / 1000; //2014-07-10 10:21:12的时间戳为:1404958872 console.log(stringTime + "的时间戳为:" + timestamp2); // 将当前时间换成时间格式字符串 var timestamp3 = 1403058804; var newDate = new Date(); newDate.setTime(timestamp3 * 1000); // Wed Jun 18 2014 console.log(newDate.toDateString()); // Wed, 18 Jun 2014 02:33:24 GMT console.log(newDate.toGMTString()); // 2014-06-18T02:33:24.000Z console.log(newDate.toISOString()); // 2014-06-18T02:33:24.000Z console.log(newDate.toJSON()); // 2014年6月18日 console.log(newDate.toLocaleDateString()); // 2014年6月18日 上午10:33:24 console.log(newDate.toLocaleString()); // 上午10:33:24 console.log(newDate.toLocaleTimeString()); // Wed Jun 18 2014 10:33:24 GMT+0800 (中国标准时间) console.log(newDate.toString()); // 10:33:24 GMT+0800 (中国标准时间) console.log(newDate.toTimeString()); // Wed, 18 Jun 2014 02:33:24 GMT console.log(newDate.toUTCString()); Date.prototype.format = function(format) { var date = { "M+": this.getMonth() + 1, "d+": this.getDate(), "h+": this.getHours(), "m+": this.getMinutes(), "s+": this.getSeconds(), "q+": Math.floor((this.getMonth() + 3) / 3), "S+": this.getMilliseconds() }; if (/(y+)/i.test(format)) { format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length)); } for (var k in date) { if (new RegExp("(" + k + ")").test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? date[k] : ("00" + date[k]).substr(("" + date[k]).length)); } } return format; } console.log(newDate.format('yyyy-MM-dd h:m:s'));
/** * 获取指定年份的第几周的开始时间戳 * @param int year 年份 * @param int week 第几周 * @return int */ function getWeek(year,week){ week = parseInt(week); var date1 = new Date(year,0,1); //1月1号 var offsetDay = date1.getDay(); //获取星期几 var offsetTimestamp = Date.parse(date1); var dayTimestamp = 86400000; //每天毫秒数 var firstDayTimestamp = 0; //第1周的第一天开始时间戳 if(offsetDay==1){ //周一 firstDayTimestamp = offsetTimestamp; }else{ //非周一 firstDayTimestamp = offsetTimestamp - dayTimestamp*(7-offsetDay); } return firstDayTimestamp + (parseInt(week)-1)*7*dayTimestamp; }
相关推荐
javascript时间戳和日期字符串相互转换代码(超简洁)_.docx
javascript时间戳和日期字符串相互转换代码(超简单) <html xmlns=http://www.w3.org/1999/xhtml> <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> [removed] // 获取...
//当前时间戳为:1403149534 console.log("当前时间戳为:" + timestamp); // 获取某个时间格式的时间戳 var stringTime = "2014-07-10 10:21:12"; var timestamp2 = Date.parse(new Date(stringTime)); timestamp2 ...
废话少说,直接上代码 代码如下: //获取当前时间: var myDate = new Date();//当前时间 var year = myDate.getFullYear();//当前年份 var month = myDate.getMonth() + 1;//当前月份 var day = myDate....
1、原生JavaScript实现字符串长度截取 2、原生JavaScript获取域名主机 3、原生JavaScript清除空格 4、原生JavaScript替换全部 5、原生JavaScript转义html标签 6、原生JavaScript还原html标签 7、原生JavaScript时间...
优秀的 一个Node.js包,用于将excel时间戳转换为JS日期。 exceldate是一个简单的实用程序函数,没有依赖项,它直接接受数字或存储在字符串中。安装yarn add exceldate# ornpm install exceldate用法一探究竟: const...
该库允许您将日期(字符串或Date实例)转换为时间戳。入门要求不确定它是否适用于 Angular <=1.2版本,但它应该可以正常工作(除非Filter API 更改)与 Angular >=1.2 。安装angular-timestamp-filter在 [ bower...
在JavaScript中不区分“字符”和“字符串”,字符也被当做字符串处理。在字符串中可以包括用于特殊目的的字符。 [removed] var hello = 你好; //双引号 var name = 'fanyoh'; //单引号 alert(hello + ...
最近在写一个时间判断脚本,需要将固定好的字符串时间转换为时间戳进行比较,在做的时候个人习惯使用chrome作为调试工具,代码基本完成之后,一切正常; 使用其他浏览器访问,好嘛,IE跟safari都不兼容,返回错误”...
日期格式化相信对于大家来说再熟悉不过,最近工作中自己利用Javascript就写了一个,现在将实现的代码分享给大家,希望对有需要的朋友们能有所帮助,感兴趣的朋友们下面来一起看看吧。
包括Unicode编码和解码、UTF-8字符串编码和解码、Base64字符串编解码、字符串MD5编码,前端非常实用的工具 图片Base64编码 对图片文件进行base64编码,直接拷贝datauri格式的数据 二维码生成器 能对网址、普通文本...
包括Unicode编码和解码、UTF-8字符串编码和解码、Base64字符串编解码、字符串MD5编码,前端非常实用的工具 图片Base64编码 对图片文件进行base64编码,直接拷贝datauri格式的数据 二维码生成器 能对网址、普通文本...
可以使用 JSON.stringify 方法,将 JavaScript 对象转换成字符串存储) (2) 全体查询 查询的结果,以文件名列表的形式呈现,按照倒序(最近的记录显示最靠前)显 示;(提示:结果保存在数组中,便于后续操作) (3) ...
实例113 字符串与HTML标记相互转换 144 实例114 运用PHP 5.0新型字符串输出XML数据 145 实例115 判断字符串中是否存在指定子串 146 2.9 正则表达式 147 实例116 验证电话号码的格式是否正确 147 实例117 验证Email...
4.5 使用字符串函数匹配和替换子字符串 4.5.1 在字符串中查找字符串:strstr()、strchr()、strrchr()和stristr() 4.5.2 查找子字符串的位置:strpos()、strrpos() 4.5.3 替换子字符串:str_replace()、substr_...
4.5 使用字符串函数匹配和替换子字符串 4.5.1 在字符串中查找字符串:strstr()、strchr()、strrchr()和stristr() 4.5.2 查找子字符串的位置:strpos()、strrpos() 4.5.3 替换子字符串:str_replace()、substr_...
时间可读 将时间格式转换为可读格式 正在安装 使用NPM NPM我时间到可读 ... 转换YYYYMMDD(YYYYMMDD) //将YYYYMMDD字符串转换为Javascript日期对象并返回。 //例如,“ 20191001”代表2019年10月1日。 年月日期。
4.5 使用字符串函数匹配和替换子字符串 4.5.1 在字符串中查找字符串:strstr()、strchr()、strrchr()和stristr() 4.5.2 查找子字符串的位置:strpos()、strrpos() 4.5.3 替换子字符串:str_replace()、substr_...
7.8字符串与数组的转换 7.9统计数组元素个数 7.10数组排序 PHP与Web页面交互(教学录像:1小时4分33秒) 8.1Web页表单元素的组成 8.2在普通的Web页中插入表单 8.3获取表单数据的两种方法 8.4PHP传参的常用方法 8.5在...