Last active
May 22, 2018 22:58
-
-
Save clc80/4308a4dc9d65d762abb370bf84d7053a to your computer and use it in GitHub Desktop.
Clock Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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