-1

we can get the milliseconds from 1970 Jan in js for the current date and time

new Date().valueOf()  // 1528191046005

form this value (1528191046005) how we can calculate the date and time, is there any way?

Vickey
  • 365
  • 1
  • 3
  • 17
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date – Robby Cornelissen Jun 05 '18 at 09:34
  • [*ECMA-262*](http://ecma-international.org/ecma-262/8.0/#sec-utc-t) provides the algorithm, but using the Date constructor is likely easier. ;-) – RobG Jun 05 '18 at 11:53

2 Answers2

0

new Date(your_unix_time * 1000) will result with the required Date object

  • The OP doesn't have a "UNIX time", they have a javascript time value and it doesn't need to be multiplied by 1,000 when passed to the Date constructor. ;-) – RobG Jun 05 '18 at 11:54
0

It should just switch back

var x=new Date().valueOf();
var y= new Date(x);
console.log(y.toDateString())