Skip to content

useTimestamp

Category
Export Size
709 B
Last Changed
7 months ago

Reactive current timestamp

Demo

Timestamp: 1757230507896

Usage

ts
import { 
useTimestamp
} from '@vueuse/core'
const
timestamp
=
useTimestamp
({
offset
: 0 })
ts
const { 
timestamp
,
pause
,
resume
} =
useTimestamp
({
controls
: true })

Component Usage

This function also provides a renderless component version via the @vueuse/components package. Learn more about the usage.

vue
<template>
  <UseTimestamp v-slot="{ 
timestamp
,
pause
,
resume
}">
Current Time: {{
timestamp
}}
<
button
@
click
="
pause
()">
Pause </
button
>
<
button
@
click
="
resume
()">
Resume </
button
>
</UseTimestamp> </template>

Type Declarations

ts
export interface 
UseTimestampOptions
<
Controls
extends boolean> {
/** * Expose more controls * * @default false */
controls
?:
Controls
/** * Offset value adding to the value * * @default 0 */
offset
?: number
/** * Update the timestamp immediately * * @default true */
immediate
?: boolean
/** * Update interval, or use requestAnimationFrame * * @default requestAnimationFrame */
interval
?: "requestAnimationFrame" | number
/** * Callback on each update */
callback
?: (
timestamp
: number) => void
} /** * Reactive current timestamp. * * @see https://vueuse.org/useTimestamp * @param options */ export declare function
useTimestamp
(
options
?:
UseTimestampOptions
<false>,
):
ShallowRef
<number>
export declare function
useTimestamp
(
options
:
UseTimestampOptions
<true>): {
timestamp
:
ShallowRef
<number>
} &
Pausable
export type
UseTimestampReturn
=
ReturnType
<typeof
useTimestamp
>

Source

SourceDemoDocs

Contributors

Anthony Fu
Anthony Fu
IlyaL
SerKo
IlyaL
OrbisK
vaakian X
sun0day
Waleed Khaled
sun0day
Jelf
Scott Bedard
Shinigami
wheat
Alex Kozack
Antério Vieira

Changelog

v14.0.0-alpha.0 on
8c521 - feat(components)!: refactor components and make them consistent (#4912)
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)

Released under the MIT License.

Join the Biggest FREE AI-Driven Development Event for Vue Developers
Save My Seat