js怎么将java Date类型输出的时间转换出来?

赵天雷 2013-12-25 02:21:56
时间格式是这样的13-12-5 14:24:00.000,带着毫秒数
我想在js里转换成Date类型,然后求两个时间的时间差,怎么处理呢?试了几个Date.parse,似乎不行啊
...全文
706 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
_拙计 2013-12-25
  • 打赏
  • 举报
回复
引用 4 楼 dut_singer 的回复:
刚找了个js函数,不太明白,但是是好用的

        function getDate(strDate) {

            var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,

             function (a) { return parseInt(a, 10) - 1; }).match(/\d+/g) + ')');

            return date;

        }
其实就是js时间格式化
赵天雷 2013-12-25
  • 打赏
  • 举报
回复
刚找了个js函数,不太明白,但是是好用的

        function getDate(strDate) {

            var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,

             function (a) { return parseInt(a, 10) - 1; }).match(/\d+/g) + ')');

            return date;

        }
别闹腰不好 2013-12-25
  • 打赏
  • 举报
回复
转换没问题,就是这个做差,最后差是什么形式
_拙计 2013-12-25
  • 打赏
  • 举报
回复
var date1 = new Date().format('yyyy-MM-dd hh:mm:ss');
//js时间格式化;
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;
}
tony4geek 2013-12-25
  • 打赏
  • 举报
回复
你在java 后台转换好就可以。

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧