Created
May 4, 2024 18:18
-
-
Save Steellgold/de61bda61e10233fe0bfae5968bebe12 to your computer and use it in GitHub Desktop.
The addZero function is used to format numbers by adding a zero in front of those less than 10, thereby enhancing the visual presentation of digital displays, such as times or dates, to make them more aesthetically pleasing and consistent.
This file contains hidden or 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 { ReactElement } from "react"; | |
export const TimeDisplay = (): ReactElement => { | |
const currentHour = new Date().getHours(); | |
const currentMinute = new Date().getMinutes(); | |
const formattedHour = addZero(currentHour); | |
const formattedMinute = addZero(currentMinute); | |
return <p>Current Time: {formattedHour}:{formattedMinute}</p>; | |
} | |
const addZero = (i: number) => { | |
return i < 10 ? `0${i}` : i; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment