D
D
doitden2014-06-27 16:24:57
JavaScript
doitden, 2014-06-27 16:24:57

How to correctly translate timestamp into time?

There is a timestamp for example 1403774400000
Using the toGMTString() function, I translate it like this:

var myDate = new Date(1403774400000);
            console.log(myDate.toGMTString()); //Thu, 26 Jun 2014 09:20:00 GMT

How to return time only in hh:mm format?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Zhak, 2014-06-27
@doitden

// создаете Date-объект с вашим timestamp
var date = new Date( unix_timestamp * 1000 );
// извлекаем часы
var hours = date.getHours();
// минуты
var minutes = date.getMinutes();
// секунды
var seconds = date.getSeconds();
// показываем в нужном формате: 11:17:23 
var time = hours + ':' + minutes + ':' + seconds;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question