Search

Back

Copy Link

Library

/

Free

/

41

Current Time & Date

41

Current Time & Date

Not loading? Preview

Made by

@frameroverrides

override

none

Override

Current Time & Date

Copy

Override

Copied to Clipboard!

Instructions

Apply to any text layer

Code Preview

import type { ComponentType } from "react"
import { useEffect, useState } from "react"

export function withDate(Component): ComponentType {
    return (props) => {
        const currentDate = new Date()
        const formattedDate = currentDate.toLocaleDateString("en-US", {
            year: "numeric",
            month: "short",
            day: "numeric",
        })

        return <Component {...props} text={formattedDate} />
    }
}

export function withTimeHM(Component): ComponentType {
    return (props) => {
        const [currentTime, setCurrentTime] = useState(null)

        useEffect(() => {
            setCurrentTime(new Date())

            const timer = setInterval(() => {
                setCurrentTime(new Date())
            }, 1000)

            return () => {
                clearInterval(timer)
            }
        }, [])

        const formattedTime = currentTime
            ? currentTime.toLocaleTimeString([], {
                  hour: "numeric",
                  minute: "2-digit",
                  hour12: true,
              })
            : "Loading..."

        return <Component {...props} text={formattedTime} />
    }
}

export function withTimeHMS(Component): ComponentType {
    return (props) => {
        const [currentTime, setCurrentTime] = useState(null)

        useEffect(() => {
            setCurrentTime(new Date())

            const timer = setInterval(() => {
                setCurrentTime(new Date())
            }, 1000)

            return () => {
                clearInterval(timer)
            }
        }, [])

        const formattedTime = currentTime
            ? currentTime.toLocaleTimeString([], {
                  hour: "numeric",
                  minute: "2-digit",
                  second: "2-digit",
                  hour12: true,
              })
            : "Loading..."

        return <Component {...props} text={formattedTime} />
    }
}

export function withSpecificTimeZone(Component): ComponentType {
    return (props) => {
        const [currentTime, setCurrentTime] = useState(null)

        useEffect(() => {
            setCurrentTime(new Date())

            const timer = setInterval(() => {
                setCurrentTime(new Date())
            }, 1000)

            return () => {
                clearInterval(timer)
            }
        }, [])

        const formattedTime = currentTime
            ? currentTime.toLocaleTimeString([], {
                  hour: "numeric",
                  minute: "2-digit",
                  second: "2-digit",
                  timeZone: "America/Toronto",
                  hour12: true,
              })
            : "Loading..."

        return <Component {...props} text={formattedTime} />
    }
}

Terms of Use for Free Assets

By accessing and using this Framer Override Library, you agree to the following terms:

All code snippets provided are available for your personal and professional use. This includes personal websites, client projects, and other website projects in Framer. You are strictly prohibited from sharing, redistributing, selling these code snippets, or creating derivative works for resale or distribution. Unauthorized sharing, distribution, or selling of these code snippets is a breach of these terms and may result in termination of your access to this library, along with potential legal action.