jquery 毫秒转换成日期,将毫秒转换为日期(jQuery / JS)

I'm a bit of a rambler, but I'll try to keep this clear -

I'm bored, so I'm working on a "shoutbox", and I'm a little confused over one thing. I want to get the time that a message is entered, and I want to make sure I'm getting the server time, or at least make sure I'm not getting the local time of the user. I know it doesn't matter, since this thing won't be used by anyone besides me, but I want to be thorough. I've looked around and tested a few things, and I think the only way to do this is to get the milliseconds since ?/?/1970 or whatever it is, since that'd be the same for everyone.

I'm doing that like so:

var time = new Date();

var time = time.getTime();

That returns a number like 1294862756114.

Is there a way to convert 1294862756114 to a more readable date, like DD/MM/YYYY HH:MM:SS?

So, basically, I'm looking for JavaScripts equivelant of PHP's date(); function.

解决方案var time = new Date().getTime();

var date = new Date(time);

alert(date.toString()); // Wed Jan 12 2011 12:42:46 GMT-0800 (PST)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值