Update Clock.jsx

This commit is contained in:
Eartharoid 2019-10-13 19:14:31 +01:00
parent 9414a35fe8
commit 735ee6def9
1 changed files with 3 additions and 8 deletions

View File

@ -1,10 +1,5 @@
import React from 'react';
const checkTime = (i) => {
if (i < 10) i = '0' + i;
return i;
};
export default class Clock extends React.Component {
constructor(...args) {
super(...args);
@ -18,12 +13,12 @@ export default class Clock extends React.Component {
const today = new Date();
let h = today.getHours();
const ampm = h >= 12 ? 'PM' : 'AM';
const m = checkTime(today.getMinutes());
// const s = checkTime(today.getSeconds());
const m = today.getMinutes();
// const s = today.getSeconds();
if (h > 12) h = h - 12;
this.setState({ date: h + ':' + m, ampm: ampm });
this.setState({ date: `${('0' + h).slice(-2)}:${('0' + m).slice(-2)}`, ampm: ampm });
this.timeout = setTimeout(() => this.startTime(), 500);
}