http://blog.sina.com.cn/s/blog_565826ac0101cvnb.html
用Ajax从后台传回Json数据,日期字符串Date(-150537600000)的转换:
function cTime(t) {
输出结果:1965-03-26
date.pattern("yyyy-MM-dd")函数:转自
http://blog.csdn.net/hemingwang0902/article/details/4511130
其他相关知识:
一、unix时间戳转普通时间:
1
2
3
4
|
var
unixtime=1358932051;
var
unixTimestamp
new
Date(unixtime*
commonTime
alert(
"普通时间为:"
+commonTime);
|
二、普通时间转unix时间戳
1
2
3
4
5
|
var
str
"2013-01-01
;
str
"/"
);
var
date
new
Date(str);
var
humanDate
new
Date(Date.UTC(date.getFullYear(),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(),
alert(humanDate.getTime()/1000
|
===============================时间戳比较大小,前提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;" οnclick="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>