<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
<script type="text/babel">
const compareTimes = (time1, time2) => {
const date1 = new Date(`2000-01-01 ${time1}`);
const date2 = new Date(`2000-01-01 ${time2}`);
if (date1 < date2) return 'Time 1 is earlier than Time 2';
if (date1 > date2) return 'Time 1 is later than Time 2';
return 'Time 1 is the same as Time 2';
const time2 = '11:45 AM';
const comparisonResult = compareTimes(time1, time2);
<div className="container">
<h3 className="title">React Js Compare Time String in 12 Hours Format</h3>
<p className="time">Time 1: {time1}</p>
<p className="time">Time 2: {time2}</p>
<p className="result">Comparison Result: {comparisonResult}</p>
ReactDOM.render(<App />, document.getElementById("app"));
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24);