1. 时间字符串格式


var dateString1 = '2016-06-15 10:22:00'; var dateString2 = '2016/06/15 10:22:00'; var dateString3 = '2016 06 15 10:22:00';

2. 中国标准时间


var date1 = new Date(); // 获取当前时间,格式为中国标准时间 var date2 = new Date(dateString1); // 将时间字符串转化为对应的中国标准时间 var date3 = new Date(时间戳); // 将时间戳转化为对应的中国标准时间

3. 时间戳 - 通过将中国标准时间转化而成


var timestamp1 = Date.parse(date1/date2); // 获取的时间戳是把毫秒改成000显示 var timestamp2 = (date1/date2).valueOf(); // 获取了当前毫秒的时间戳 var timestamp3 = (date1/date2).getTime(); // 获取了当前毫秒的时间戳

4. 获取自定义格式的日期


// 1. 若小于10,前面加0 function isZero(m){ return m<10?'0'+m:m } // 将字符串转为Date格式,获取对应的年、月、日、时、分、秒。组合格式 function formatDate(shijianchuo) { //时间戳是整数,否则要parseInt转换
var time = new Date(shijianchuo); // 需要使用Date格式进行日期转化,若是时间戳、字符串时间,需要通过new Date(..)转化 var y = time.getFullYear(); var m = time.getMonth()+1; var d = time.getDate(); var h = time.getHours(); var mm = time.getMinutes(); var s = time.getSeconds(); return y+'/'+isZero(m)+'/'+isZero(d)+' '+isZero(h)+':'+isZero(mm)+':'+isZero(s); } // 调用 -- 输出: 2019/01/01 10:00:00 formatDate('2019 01 01 10:00:00');

JS 时间格式 相互转化的更多相关文章

  1. JS时间格式CST转GMT

    转换方法:JS 时间格式CST转GMT 时区和Date:Java中的Date和时区转换

  2. js 时间格式转换

    js时间格式转换 格式化时间转成时间戳 //格式化转时间戳(单位秒) function strtotime(strtime) { strtime = strtime.substring(0, 19); ...

  3. moment.js 时间格式转换

    moment.js 时间格式转换 moment.js 时间转化 bug 格式错误 bug 02:00 => 14:00 format HH 与 hh HH === 24 小时制 hh === 1 ...

  4. JS时间格式 GMT格式转换

    JavaScript时间格式转换总结 1.当前系统区域设置格式(toLocaleDateString和toLocaleTimeString) 例子:(new Date()).toLocaleDateS ...

  5. JS 时间格式CST转GMT

    近几天,在做百度地图时,需要转换时间格式并做显示,但是发现显示的时间格式,出现了错乱,二者的日期和小时都出现了变动.例如: 原始时间格式:Thu Aug 18 20:38:54 CST 2016 转换 ...

  6. JS时间格式和时间戳的相互转换

    时间戳转化为日期的方式 ; var newDate = new Date(); newDate.setTime(timestamp * ); // Mon May 28 2018 console.lo ...

  7. JS时间格式和时间戳的互转

    //时间格式转为时间戳 function sjc(){ var date = new Date(); //时间对象 var str = date.getTime(); //转换成时间戳 } //时间戳 ...

  8. js ---- 时间格式

    Js获取当前日期时间及其它操作 var myDate = new Date(); myDate.getYear();        //获取当前年份(2位) myDate.getFullYear(); ...

  9. js时间格式转换

    在javascript中直接输出Date得到的结果是这样的: function date(){ var date = new Date(); alert(date); } 结果是:Mon Jun 15 ...

随机推荐

  1. Win10中用yolov3训练自己的数据集全过程(VS、CUDA、CUDNN、OpenCV配置,训练和测试)

    在Windows系统的Linux系统中用yolo训练自己的数据集的配置差异很大,今天总结在win10中配置yolo并进行训练和测试的全过程. 提纲: 1.下载适用于Windows的darknet 2. ...

  2. Delphi VS C语言类型转换对照

    Delphi VS C语言类型转换对照   When converting C function prototypes to Pascal equivalent declarations, it's ...

  3. Python数据类型详解——元组

    Python数据类型详解--元组 有时候我们的列表数据不想被别人修改时该怎么办? 此时,就可以使用元组来存放,元祖又称为只读列表,不能修改 定义方式:与列表类似,将列表的[]换成()即可. 特性: 1 ...

  4. 【selenium】- webdriver常见元素定位(下)

    本文由小编根据慕课网视频亲自整理,转载请注明出处和作者. 1.table 表格如下: 使用firebug查看: 代码实现: 1)显示出表格所有内容 2)显示表格某个特定的数值 自动化测试框架: 关键字 ...

  5. hdu6219 Empty Convex Polygons (最大空凸包板子

    https://vjudge.net/contest/324256#problem/L 题意:给一堆点,求最大空凸包面积. 思路:枚举凸包左下角点O,dp找出以这个点为起始位置能构成的最大空凸包面积, ...

  6. 牛客网暑期ACM多校训练营(第四场) G Maximum Mode 思维

    链接:https://www.nowcoder.com/acm/contest/142/G来源:牛客网 The mode of an integer sequence is the value tha ...

  7. poj 3660Cow Contest

    题目链接:http://poj.org/problem?id=3660 有n头奶牛还有m种关系a,b表示a牛逼b彩笔,所以a排名比b高 最后问你给出的关系最多能确定多少头奶牛的排名,而且给出的数据不会 ...

  8. ZOJ 3876 May Day Holiday

    As a university advocating self-learning and work-rest balance, Marjar University has so many days o ...

  9. Shell脚本分析服务器性能

    概述 我们原先在服务器上想分析性能指标,需要执行一系列的linux命令.对于linux命令不熟悉的人来说,比较困难 现在有一套集成的shell脚本,把常用的linux命令都包含在里面,一键式分析性能瓶 ...

  10. 【LeetCode】105#从前序与中序遍历序列构造二叉树

    题目描述 根据一棵树的前序遍历与中序遍历构造二叉树. 注意: 你可以假设树中没有重复的元素. 例如,给出 前序遍历 preorder = [3,9,20,15,7] 中序遍历 inorder = [9 ...