用Ajax从后台传回Json数据,日期字符串Date(-150537600000)的转换:

function cTime(t) {
          if (t != "") {
             var time=parseInt(t.substring(6, t.length - 2));//截取字符串
                  commonTime= new Date(time);
                   returnreturn commonTime.pattern("yyyy-MM-dd");
                    }
                }
输出结果:1965-03-26


date.pattern("yyyy-MM-dd")函数:转自 http://blog.csdn.net/hemingwang0902/article/details/4511130

其他相关知识:

一、unix时间戳转普通时间:

var  unixtime=1358932051;
var  unixTimestamp = new  Date(unixtime* 1000); 
commonTime = unixTimestamp.toLocaleString();
alert( "普通时间为:" +commonTime);
二、普通时间转unix时间戳

var  str = "2013-01-01 00:00:00" ;
str = str.replace(/-/g, "/" );
var  date = new  Date(str); 
var  humanDate = new  Date(Date.UTC(date.getFullYear(),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(), date.getSeconds())); 
alert(humanDate.getTime()/1000 - 8*60*60);

时间戳比较大小,前提10分 发起活动,


form:

<form id="form" action="{$post_url}" method="post" class="form-horizontal form-center" name="myform">

<button

class="btn submit-btn ajax-post"

id="submit"

type="submit"

target-form="form-horizontal"

style="margin-left:126px;"

onclick="checktime(this.form)"

>

{$submit_name|default='确 定'}

</button>

</form>

js: 
<script type="text/javascript">
       function checktime(form){
	  //当前时间戳
	    var timestamp = Date.parse(new Date());
            timestamp = timestamp / 1000;
			//alert(timestamp);
 
           //用户填写的活动开始时间戳
	     var starttime= form.act_starttime.value;  //字符型日期
             var str =starttime;
             str = str.replace(/-/g,"/");
             var date = new Date(str); 
             var humanDate = new Date(Date.UTC(date.getFullYear(),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(), date.getSeconds())); 
             user_starttime = (humanDate.getTime()/1000 - 8*60*60);  	  
			//alert((user_starttime-timestamp)/60<10);
			 if((user_starttime-timestamp)/60<10){
				alert("活动必须提前10分钟发起");
				return false;
			}
		 }
</script>


您已经阅读00:00:00欢迎留言评论,喜欢的话就为作者点个赞或者赏颗糖吧! 分享