Reputation: 2382
I have the following code
new Date(1501796503599)
which returns the value
Fri Aug 04 2017 03:11:43 GMT+0530 (IST)
I need the above value to be displayed as "Today, 3:11 am"
. Is there a way to do this
Upvotes: 1
Views: 52
Reputation: 175
var monthName = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
$(function(){
var newDate = '';
newDate = new Date(1501796503599)
if (newDate != '')
var str = newDate.getDate() + "-" + monthName[newDate.getMonth()] + "-" + newDate.getFullYear()+
" " + newDate.getHours() + ":" + newDate.getMinutes() + ":" + newDate.getSeconds();
console.log(str);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
try this one.
Upvotes: 0
Reputation: 126
you can simply check using javascript without any dependencies.
var yourDate = new Date(1501796503599);
var today = new Date();
var isToday = (today.toDateString() == yourDate.toDateString());
if(isToday){
yourDate = "Today, " + yourDate.toLocaleTimeString();
}
else{
yourDate;
}
Upvotes: 0
Reputation: 2382
var time = moment(1501796503599).calendar();
console.log(time);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js"></script>
Upvotes: 2