日期转换成json以后会变成一串数字,如何把数字转换为日期
2015-07-24 15:59
381 查看
java中
package com.amssy.controller;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class TestJsonDate {
/**
* @param args
*/
public static void main(String[] args) {
long unixstamp=1437646938000l;
Date dt=new Date(unixstamp);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
System.out.println(sdf.format(dt));
}
}
js
<html>
<head>
<script type="text/javascript">
var xx='/Date(1437646938000)/';
var tt=xx.substring(6,xx.length-2);
var jsonDate=new Date(parseInt( xx.substring(6,xx.length-2)));
alert(new Date());
alert(jsonDate);
Date.prototype.format = function(format){
var o = {
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}
if(/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(var k in o) {
if(new RegExp("("+ k +")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
}
}
return format;
}
var now=new Date();
var nowStr = jsonDate.format("yyyy-MM-dd hh:mm:ss");
alert(nowStr);
</script>
</head>
<body>
</body>
</html>
package com.amssy.controller;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class TestJsonDate {
/**
* @param args
*/
public static void main(String[] args) {
long unixstamp=1437646938000l;
Date dt=new Date(unixstamp);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
System.out.println(sdf.format(dt));
}
}
js
<html>
<head>
<script type="text/javascript">
var xx='/Date(1437646938000)/';
var tt=xx.substring(6,xx.length-2);
var jsonDate=new Date(parseInt( xx.substring(6,xx.length-2)));
alert(new Date());
alert(jsonDate);
Date.prototype.format = function(format){
var o = {
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}
if(/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(var k in o) {
if(new RegExp("("+ k +")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
}
}
return format;
}
var now=new Date();
var nowStr = jsonDate.format("yyyy-MM-dd hh:mm:ss");
alert(nowStr);
</script>
</head>
<body>
</body>
</html>
相关文章推荐
- javascript属性一览
- js 返回页面顶部 代码
- vax关于js方面的一些设置
- 【HTML】通过不同的分辨率调用不同的css,两种方法:css本身判断、js调用css
- js中将字符串转换成json的三种方式
- javascript 判断空格(包括空格、tab键等)
- Json格式对象转换为XML
- XML vs JSON 谁是数据交换格式之王?
- javascript实现禁止鼠标滚轮事件
- js读取解析JSON类型数据
- Js笛卡尔乘积
- jsp页面修改成html页面
- 四种参数传递的形式――URL,超链接,js,form表单
- js处理小数
- JavaScript高级编程【BOM-window对象】
- hammer.js实现背景图手势缩放调整位置
- hammer.js实现背景图手势缩放调整位置
- JS 控制文本框只能输入中文/中文、英文、数字、空格/中文、英文、数字、小数点
- jsp表单验证汇总
- xx.offsetLeft与xx.style.left的区别