当前位置: 移动技术网 > IT编程>开发语言>JavaScript > JS自定义函数实现时间戳转换成date的方法示例

JS自定义函数实现时间戳转换成date的方法示例

2017年12月12日  | 移动技术网IT编程  | 我要评论

本文实例讲述了js自定义函数实现时间戳转换成date的方法。分享给大家供大家参考,具体如下:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>获取当前年/月/日(www.jb51.net)</title>
</head>
<body>
<script>
function unixtodate(unixtime, timezone) {
  if (typeof (timezone) == 'number')
  {
   unixtime = parseint(unixtime) + parseint(timezone) * 60 * 60;
  }
  var now = new date(unixtime * 1000);
  var year=now.getfullyear();
  var month=now.getmonth()+1;
  var date=now.getdate();
  var hour=now.gethours();
  var minute=now.getminutes();
  return year+"/"+month+"/"+date+" "+hour+":"+minute ;
}
var m_time = parseint(new date().gettime()/1000); 
var m_date = unixtodate(m_time) ;
document.write(m_date);
</script>
</body>
</html>

运行结果:

2017/8/27 12:4

ps:这里再为大家推荐几款时间及日期相关工具供大家参考使用:

在线日期/天数计算器:

在线日期计算器/相差天数计算器:

在线日期天数差计算器:

unix时间戳(timestamp)转换工具:

更多关于javascript相关内容感兴趣的读者可查看本站专题:《javascript时间与日期操作技巧总结》、《javascript查找算法技巧总结》、《javascript错误与调试技巧总结》、《javascript数据结构与算法技巧总结》、《javascript遍历算法与技巧总结》及《javascript数学运算用法总结

希望本文所述对大家javascript程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网