//把日期转换成时间戳

function get_unix_time(time1){
    var newstr = time1.replace(/-/g,'/');
    var date =  new Date(newstr);
    var time_str = date.getTime().toString();
    return time_str.substr(0, 10);
}

一.时间转换时间戳
function transdate(endTime){
var date=new Date();
date.setFullYear(endTime.substring(0,4));
date.setMonth(endTime.substring(5,7)-1);
date.setDate(endTime.substring(8,10));
date.setHours(endTime.substring(11,13));
date.setMinutes(endTime.substring(14,16));
date.setSeconds(endTime.substring(17,19));
return Date.parse(date)/1000;
}
二.时间戳转换时间
(1):转换成 2011-3-16 16:50:43 格式:

function getDate(tm){
var tt=new Date(parseInt(tm) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ")
return tt;
}
(2):转换成 2011年3月16日 16:50:43:

function getDate(tm){
var tt=new Date(parseInt(tm) * 1000).toLocaleString()
return tt;
}

(3):转换成 2011年3月16日 16:50

function getDate(tm){
var tt=new Date(parseInt(tm) * 1000).toLocaleString().substr(0,16);
return tt;
}

//计算几天后的日期,js天数计算、时间计算

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>计算几天后的日期,js天数计算、时间计算-www.jbxue.com</title>
<style type="text/css">
<!--
body {  font-family: "宋体"; font-size: 9pt; margin-top: 0px; margin-left: 0px; margin-right: 0px}
A { COLOR: black; FONT-SIZE: 9pt; FONT-WEIGHT: 400; TEXT-DECORATION: none }
A:hover { COLOR: red; FONT-SIZE: 9pt; FONT-WEIGHT: 400; TEXT-DECORATION: underline }
a:active     { font: 9pt "宋体"; cursor: hand; color: #FF0033 }
-->
</style>
</head>
<body>

<center><font color=red face="隶书" size=6>记录几天后的日期</font></center>
<center>
<table border=0 bordercolor=blue borderlight=green style="border-collapse: collapse" cellpadding="0" cellspacing="0">
<tr><td align=center><font size=5 color=red face="Arial, Helvetica, sans-serif"><strong>下面为效果显示区!</strong></font></td></tr><tr><td align=center> <script language="JavaScript">
<!-- Begin
function AddDays(form) {
  DaysToAdd=document.form.DaysToAdd.value;
  var now=new Date();
  var newdate=new Date();
  var newtimems=newdate.getTime()+(DaysToAdd*24*60*60*1000);
  newdate.setTime(newtimems);
  document.form.display.value=newdate.toLocaleString();
}
// End -->
</script>
<form name=form>
<input type=text name=DaysToAdd size=4 value=10 onFocus="this.select()" onMouseOver="this.focus()">
<input type=button value="天后的日期将是.." onClick="AddDays(this.form)" name="button">
<input type=text name="display" size=20 value="">
</form>
</td></tr>
</table></center>
<center>
<SCRIPT LANGUAGE="JavaScript">
<!-- hide
function goHist(a)
{//www.jbxue.com
   history.go(a);
}
//-->
</script></center>
</body>
</html>

js 时间格式与时间戳的相互转换和计算几天后的日期是哪一天的更多相关文章

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

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

  2. js 时间格式与时间戳的相互转换示例代码

    一.时间转换时间戳 function transdate(endTime){ var date=new Date(); date.setFullYear(endTime.substring(0,4)) ...

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

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

  4. 时间戳显示为多少分钟前,多少天前的JS处理,JS时间格式化,时间戳的转换

    var dateDiff = function (timestamp) { // 补全为13位 var arrTimestamp = (timestamp + '').split(''); for ( ...

  5. js 时间格式转换

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

  6. JS 时间格式CST转GMT

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

  7. 关于javascript中时间格式和时间戳的转换

    当前时间获取的各种函数: var myDate = new Date();myDate.getYear();        //获取当前年份(2位),已经不推荐使用myDate.getFullYear ...

  8. JS时间格式CST转GMT

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

  9. moment.js 时间格式转换

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

随机推荐

  1. SettingsEditplus

      迁移时间:2017年5月20日10:51:51Author:Marydon官网下载 http://www.editplus.com/设置一 1.修改字体大小及背景色 首选项-->Genera ...

  2. 类的专有方法(__getitem__和__setitem__)

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #http://www.imooc.com/code/6252 #类的专有方法(__getitem__和__s ...

  3. windows执行命令来运行loadrunner录制好的脚本(收藏)

    SET M_ROOT=D:Mercury InteractiveMercury LoadRunnerincd %M_ROOT% wlrun.exe -TestPath D:ceshi10Scenari ...

  4. Linux下PHP5.5编译参数详解

    一.配置参数 ./configure --prefix=/data/app/php --with-config-file-path=/etc --with-mysql=/usr\ --with-mys ...

  5. jquery实现 批量右移

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...

  6. js createElement appendChild createTextNode用法

    xml不支持innerHTML 1 <p id="bj">北京</p> <script type="text/javascript" ...

  7. POJ 2965 The Pilots Brothers' refrigerator (DFS)

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15136 ...

  8. 【js】replace()

    replace方法的语法是: stringObj.replace(rgExp, replaceText) 其中stringObj是字符串(string),reExp可以是正则表达式对象(RegExp) ...

  9. WebApi和MVC的区别

    使用上区分,mvc主要用于建站,web api主要用于构建http服务,当然你非要用mvc来构建Uri式的Api也行,不过显然是没有这个必要的,一个不恰当的比喻就像是你也可以玩破解版的单机游戏,也可以 ...

  10. sqlserver中将varchar类型转换为int型再进行排序的方法

    sql中把varchar类型转换为int型然后进行排序,如果我们数据库的ID设置为varchar型的 在查询的时候order by id的话 如果我们数据库的ID设置为varchar型的 在查询的时候 ...