How to convert this timestamp 1382086394000 to 2013-10-18 08:53:14 using a function in javascript? Currently I have this function:

如何使用javascript中的函数将这个时间戳1382086394000转换为2013-10-18 08:53:14 ?目前我有这个功能:

function cleanDate(d) {return new Date(+d.replace(/\/Date\((\d+)\)\//, '$1'));}

7 个解决方案

#1


76

The value 1382086394000 is probably a time value, which is the number of milliseconds since 1970-01-01T00:00:00Z. You can use it to create an ECMAScript Date object using the Date constructor:

值1382086394000可能是一个时间值,它是1970-01-01T00:00:00Z之后的毫秒数。您可以使用它使用日期构造器创建ECMAScript日期对象:

var d = new Date(1382086394000);

How you convert that into something readable is up to you. Simply sending it to output should call the internal (and entirely implementation dependent) toString method that usually prints the equivalent system time in a human readable form, e.g.

如何把它转换成可读的东西取决于你。简单地将其发送到输出应该调用内部(完全依赖于实现)的toString方法,该方法通常以人类可读的形式打印等效的系统时间,例如。

Fri Oct 18 2013 18:53:14 GMT+1000 (EST) 

In ES5 there are some other built-in formatting options:

在ES5中还有一些其他内置的格式选项:

  • toDateString
  • toDateString
  • toTimeString
  • toTimeString
  • toLocaleString
  • toLocaleString

and so on. Note that most are implementation dependent and will be different in different browsers. If you want the same format across all browsers, you'll need to format the date yourself, e.g.:

等等。注意,大多数都是依赖于实现的,并且在不同的浏览器中是不同的。如果你想在所有浏览器中使用相同的格式,你需要自己格式化日期,例如:

alert(d.getDate() + '/' + (d.getMonth()+1) + '/' + d.getFullYear());

更多相关文章

  1. js和php时间戳的问题
  2. 从服务器(任何服务器)获取当前日期和时间。仅限javascript
  3. 输入类型=日期的日期显示为dd-mm-yyyy格式
  4. 在jQuery datetimepicker中禁用特定时间
  5. 根据用户时区显示当地时间 php+javascript
  6. JavaScript动态显示时间
  7. 我可以使用onBlur事件对TextBox进行日期检查吗?
  8. Day.js :一个轻量的处理时间和日期的 JavaScript 库
  9. 【第三篇】说说javascript处理时间戳

随机推荐

  1. 关于Android 关于EditText输入限制等小结
  2. android swipeRefreshLayout 下拉刷新 go
  3. android studio不会导入及出现各种问题怎
  4. HwBinder驱动篇-Android10.0 HwBinder通
  5. PHP 即将来到 Google Android?
  6. android:layout_gravity 和 android:grav
  7. Android将允许纯C/C++开发应用
  8. Android的一些基本概念
  9. Android主流三方库源码分析(五、深入理解R
  10. Android常用类库包介绍