base-chat icon indicating copy to clipboard operation
base-chat copied to clipboard

chatMessage.timeSent in message.component.ts is not showing the current time

Open dipali09 opened this issue 8 years ago • 3 comments

I am having an error regarding timeStamp.In chat.service.ts U I am applying the code below. this.chatMessages.push({ message:msg, timeSent:this.timestamp, email:email, userName:"this.userName" }); But it's not showing anything for the timeSent on the console and not in the firebase database. I am not having any idea how to debug it.

dipali09 avatar Nov 12 '17 13:11 dipali09

what have you put in your: getTimeStamp(){ }

in chat.services.ts?

ghost avatar Nov 27 '17 22:11 ghost

` getTimeStamp(){

const now=new Date();
const date=now.getFullYear()+'/'+(now.getMonth()+1)+'/'+now.getDay();
const time=now.getHours()+'/'+now.getMinutes()+'/'+now.getSeconds();
return(now);

}`

dipali09 avatar Nov 28 '17 14:11 dipali09

Change it to this, and it should work:

getTimeStamp(){ const now = new Date(); const date = now.getUTCFullYear() + '/' + (now.getUTCMonth() + 1) + '/' + now.getUTCDate(); const time = now.getUTCHours() + ':' + now.getUTCMinutes() + ':' + now.getUTCSeconds();

         return ( date + ' ' + time );

}

ghost avatar Nov 28 '17 22:11 ghost