I'm building a twitter interface and I want to display the times like Twitter itself.
I perform a GET request and grab the tweet, I then pass it into moment.js
in order to convert it.
Here is a code snippet of this:
client.get('direct_messages', {screen_name: 'theclearytheory', count: '3'}, function(error, messages, response){
if(!error){
var privateMessageTime = [];
for(var i=0; i < messages.length; i++){
console.log(messages[i].created_at);
privateMessageTime.push(moment(messages[i].created_at).fromNow());
}
} else {
console.log(error)
}
Right now, this DOES work fine. If I get back Sun Oct 02 11:59:43 +0000 2016
then the program correctly turns this into: 2 months ago
.
The problem is that I'm getting this warning message in the console:
Deprecation warning: value provided is not in a recognized ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info. Arguments:
[0] _isAMomentObject: true, _isUTC: false, _useUTC: false, _l: undefined, _i: Fri Jul 22 10:19:18 +0000 2016, _f: undefined, _strict: undefined, _locale: [object Object]
I have scoured over the documentation it links to but I just can't work out how to work with this. If anyone has any experience with this (or is that much smarter than me), I'd really appreciate any help please!
As stated in the parsing docs:
Warning: Browser support for parsing strings is inconsistent. Because there is no specification on which formats should be supported, what works in some browsers will not work in other browsers.
For consistent results parsing anything other than ISO 8601 strings, you should use String + Format
Since you are getting Sun Oct 02 11:59:43 +0000 2016
you will have:
moment(messages[i].created_at, 'ddd MMM DD HH:mm:ss Z YYYY').fromNow()
instead of moment(messages[i].created_at).fromNow()
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments