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))
moment(timestamp * 1000).format('HH:mm:ss')
if you want to have time part as string. – Lackingmoment(moment.unix(epochtimestamp).format("HH:mm:ss"), "HH:mm:ss");
– Saturdaymoment().isBefore()
andmoment().isAfter()
can be use for comparison – Saturday