I'm new into coding and I'm trying to format date as DD/MM/YYYY and time as HH:MM using React Moment. I tried many methods with no success. It would be great if anyone could help me with this issue, as I'm still learning the basics.
How am I supposed to format {props.date} and {props.time} to make it more user-friendly?
Here's the code that I have:
import React, { Component } from "react";
import CreatedAtShow from "./CreatedAtShow";
import { Opportunities } from "../requests";
import { OpportunityShowPage } from "./OpportunityShowPage";
import moment from "react-moment";
function OpportunityDetails(props) {
return (
<div>
<h2>
Opportunity: <br />
{props.title}
</h2>
<p></p>
<h3>
Description: <br />
{props.description}
</h3>
<p>Tag:{props.tags}</p>
<p>Date:{props.date}</p>
<p>Time: {props.time}</p>
<p>Where: {props.where}</p>
<p>Contact information: {props.contact}</p>
<p><CreatedAtShow created_at={props.created_at} /></p>
<button className="ui button"
onClick={() => {
props.editOpportunity(props.id);
}}
>
Edit
</button>
<button className="ui button"
onClick={() => props.deleteOpportunity(props.id)
// props.deleteOpportunity(props.id);
}>
Delete
</button>
</div>
);
}
export default OpportunityDetails;
props.dateandprops.timeare? Moment.js has a.parseand a.formatfunction, have you used those before?