50
rated 0 times
[
57]
[
7]
/ answers: 1 / hits: 28764
/ 8 Years ago, fri, december 2, 2016, 12:00:00
I have epoch time stamp value and I want to extract the Time from it.
For example: input 1480687432 i.e.(Fri Dec 02 2016 14:03:52 GMT+0530 (IST))
output 14:03:52
, I want to compare it with sunset/sunrise time (for future surrise/sunset timings also) to find out whether it is day or night. I am using below approach, can anyone please suggest the better approach than this in javascript
of in moment.js
var input = 1480687432; // i.e.(Fri Dec 02 2016 14:03:52 GMT+0530 (IST))`
// output 14:03:52
function getTimeFromDate(timestamp) {
var date = new Date(timestamp * 1000);
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
var time = new Date();
return time.setHours(hours, minutes, seconds);
}
console.log(getTimeFromDate(1480687432))
More From » date