Skip to content

Commit 0bb5e55

Browse files
committed
Formatted Date
1 parent 31e807e commit 0bb5e55

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"antd": "^4.4.2",
1111
"axios": "^0.19.2",
1212
"bootstrap": "^4.5.0",
13+
"date-fns": "^2.15.0",
1314
"eslint-config-react-app": "^5.2.1",
1415
"express": "^4.17.1",
1516
"html-react-parser": "0.0.4",

src/components/Comments.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from "react";
22
import { Link } from "react-router-dom";
3-
import { connect } from "react-redux";
3+
import { formatDistanceToNow } from "date-fns";
44
//import Like from "./Like";
55
import "../styles/styling.sass";
66

@@ -14,6 +14,7 @@ const Comments = (props) => {
1414
</h6>
1515
<ul className="list-group">
1616
{props.comments.map((comment, index) => {
17+
var date = new Date(comment.createdAt);
1718
return (
1819
// <li className="list-group-item" key={index}>
1920
// <p>{comment.body}</p>-
@@ -96,7 +97,7 @@ const Comments = (props) => {
9697
{comment.user.name}
9798
</Link>
9899
<br />
99-
<b>Date - </b> {comment.createdAt.substring(0, 10)}
100+
<b>{formatDistanceToNow(date)} ago </b>
100101
</div>
101102
</div>
102103
<br />

0 commit comments

Comments
 (0)