wesdoyle / base-chat

A simple chat application built using Angular and Firebase
52 stars 52 forks source link

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

Open dipali09 opened 6 years ago

dipali09 commented 6 years ago

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.

ghost commented 6 years ago

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

in chat.services.ts?

dipali09 commented 6 years ago

` getTimeStamp(){

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

}`

ghost commented 6 years ago

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 );

}