//时间转换成时间戳
function DateToUnix(string) {
var f = string.split(' ', 2);
var d = (f[0] ? f[0] : '').split('-', 3);
var t = (f[1] ? f[1] : '').split(':', 3);
var time = (new Date(
parseInt(d[0], 10) || null,
(parseInt(d[1], 10) || 1) - 1,
parseInt(d[2], 10) || null,
parseInt(t[0], 10) || null,
parseInt(t[1], 10) || null,
parseInt(t[2], 10) || null
)).getTime() / 1000
return time;
}
//GMT时间格式转换成字符串
function GMTToStr(time) {
let date = new Date(time)
let Str = date.getFullYear() + '-' +
(date.getMonth() + 1) + '-' +
date.getDate() + ' ' +
date.getHours() + ':' +
date.getMinutes() + ':' +
date.getSeconds()
return Str
}

//时间转换成GMT格式
function parserDate(date) {
var t = Date.parse(date);

if(!isNaN(t)) {
return new Date(Date.parse(date.replace(/-/g, "/")));
} else {
return new Date();
}
};

js 时间转换的更多相关文章

  1. JS 时间转换函数 字符串时间转换毫秒(互转)

    字符串转化为日期 let util = function(){ Date.prototype.Format = function(fmt) { var o = { "M+" : t ...

  2. JS时间转换的一个坑位

    在做项目的时候,无意发现了一个小东西. new Date('2018-05-15') new Date('2018-5-15') 输出的结果是不同的,相差了8小时.然后让我回忆到之前看的一个时间转换函 ...

  3. JS时间转换,url编码,jquery返回类型等问题

    1.当时间被转换为json格式后会被转换成 /Date(...)/ 这种格式,其中...为时间转换成妙后的一串整数 function changeDateFormat(cellval) { )); v ...

  4. js时间转换相关

    1.json时间格式转换 function ChangeDateFormat(jsondate) { if (!jsondate||jsondate.length < 1) {return &q ...

  5. js时间转换

    1. 将时间戳转换成日期格式 // 简单的一句代码 var date = new Date(时间戳); //获取一个时间对象 /** 1. 下面是获取时间日期的方法,需要什么样的格式自己拼接起来就好了 ...

  6. js时间转换,能够把时间转换成yyyymmdd格式或yyyymm格式

    //type为1则转换成yyyymmdd格式,type为2则转换成yyyymm格式 function formatTime(time,type){ var temp_time=new Number(t ...

  7. js 时间转换毫秒的四种方法(转)

    将时间转换为毫秒数的方法有四个: Date.parse()Date.UTCvalueOf()getTime() 1. Date.parse():该方法接受一个表示日期的字符串参数,然后尝试根据这个日期 ...

  8. Js 日期转换函数(UTC时间转换及日期想加减)

    IOS上Js日期转换中new Date("yyyy-mm-dd")不能正常工作,必须使用new Date("yyyy/MM/dd"); 日期相加减: Date. ...

  9. js时间格式转换

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

随机推荐

  1. [Javascript] Deep Search nested tag element in DOM tree

    // For example you want to search for nested ul and ol in a DOM tree branch // Give example <ol&g ...

  2. [Python] Create a minimal website in Python using the Flask Microframework

    How to install Flask Use Flask to create a minimal website Build routes in Flask to respond to websi ...

  3. Web端即时通讯、消息推送的实现

    https://blog.csdn.net/DeepLies/article/details/77726823

  4. HDU 5380 Travel with candy 单调队列

    pid=5380">链接 题解链接:http://www.cygmasot.com/index.php/2015/08/16/hdu_5380 题意: n C 一条数轴上有n+1个加油 ...

  5. 火狐Vimperator插件

    http://www.iplaysoft.com/vimium-and-vimperator.html http://wangbixi.com/x2923/comment-page-1/

  6. 2017-3-10 leetcode 229 238 268

    今天登陆leetcode突然发现531被锁了,有种占了便宜的感觉哈哈哈! ================================================ leetcode229 Ma ...

  7. 院校-国外-美国:斯坦福大学( Stanford)

    ylbtech-院校-国外-美国:斯坦福大学( Stanford) 斯坦福大学(Stanford University),全名小利兰·斯坦福大学(Leland Stanford Junior Univ ...

  8. 【docker】python: can't open file 'helloworld.py': [Errno 13] Permission denied

    运行容器提示权限问题 docker run  -v $PWD/myapp:/usr/src/myapp  -w /usr/src/myapp python:3.5 python helloworld. ...

  9. Centos 6 搭建邮箱服务器教程

    Centos 6 搭建邮箱服务器主要是是包括了Postfix, Dovecot和 MySQL了,下文我们详细的为各位介绍Centos 6 搭建邮箱服务器教程(Postfix, Dovecot和 MyS ...

  10. mysql在第一次查询的时候很慢,第二次查询就比较快的原因?

    1.默认 query_cache 是打开的 你使用 show global variables like '%query_cache%'; 确认一下有没有打开,如果打开了.第一次查询读数据文件,第二次 ...