Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clock Component
import React, { Component } from 'react';
class Clock extends React.Component {
render() {
const currentTime = new Date(),
hours = currentTime.getHours(),
minutes = currentTime.getMinutes(),
seconds = currentTime.getSeconds(),
ampm = hours >= 12? 'pm': 'am';
return(
<div className="clock"> {
hours == 0 ? 12: (hours > 12) ?
hours - 12: hours
}:
{
minutes > 9 ? minutes: `0${minutes}`
}:
{
seconds > 0 ? seconds: `0${seconds}`
}
{ampm}
</div>
)
}
}
export default Clock;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.