I have a small need where i want to convert a timestamp stored in a variable say doc.creation_time
to a format [year,month,day]
example:
doc.creation_time
= 1537492812
this should be converted to [2018,38,Fri]
Can someone help
I have a small need where i want to convert a timestamp stored in a variable say doc.creation_time
to a format [year,month,day]
example:
doc.creation_time
= 1537492812
this should be converted to [2018,38,Fri]
Can someone help
var creation_time = 1537492812;
var date = new Date(creation_time * 1000);
var weekday = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
// UTC
console.log(date.getUTCFullYear(), date.getUTCMonth() + 1, weekday[date.getUTCDay()]);
// Local
console.log(date.getFullYear(), date.getMonth() + 1, weekday[date.getDay()]);
You can use momentjs for your requirement
var creation_time = 1537492812;
//var date = moment.unix(creation_time).format('YYYY,MM,ddd');
var date = moment.unix(creation_time).format('YYYY,w,ddd');
var result = date.split(',');
console.log(result);
var creation_time = 1537492812;
//var date = moment.unix(creation_time).format('YYYY,MM,w, ddd');
var date = moment.unix(creation_time).format('YYYY,w,ddd');
var result = date.split(',');
console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.js"></script>