Skip to content
On this page

useTimestamp

Category
Last Changed
3 months ago

Reactive current timestamp

Demo

Timestamp: 1646465381573

Usage

import { useTimestamp } from '@vueuse/core'

const timestamp = useTimestamp({ offset: 0 })
import { useTimestamp } from '@vueuse/core'

const timestamp = useTimestamp({ offset: 0 })
const { timestamp, pause, resume } = useTimestamp({ controls: true })
const { timestamp, pause, resume } = useTimestamp({ controls: true })

Component

This function also provides a renderless component version via the @vueuse/components package. Learn more about the usage.
<UseTimestamp v-slot="{ timestamp, pause, resume }">
  Current Time: {{ timestamp }}
  <button @click="pause()">Pause</button>
  <button @click="resume()">Resume</button>
</UseTimestamp>
<UseTimestamp v-slot="{ timestamp, pause, resume }">
  Current Time: {{ timestamp }}
  <button @click="pause()">Pause</button>
  <button @click="resume()">Resume</button>
</UseTimestamp>

Type Declarations

export interface TimestampOptions<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
}
/**
 * Reactive current timestamp.
 *
 * @see https://vueuse.org/useTimestamp
 * @param options
 */
export declare function useTimestamp(
  options?: TimestampOptions<false>
): Ref<number>
export declare function useTimestamp(options: TimestampOptions<true>): {
  timestamp: Ref<number>
} & Pausable
export declare type UseTimestampReturn = ReturnType<typeof useTimestamp>
export interface TimestampOptions<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
}
/**
 * Reactive current timestamp.
 *
 * @see https://vueuse.org/useTimestamp
 * @param options
 */
export declare function useTimestamp(
  options?: TimestampOptions<false>
): Ref<number>
export declare function useTimestamp(options: TimestampOptions<true>): {
  timestamp: Ref<number>
} & Pausable
export declare type UseTimestampReturn = ReturnType<typeof useTimestamp>

Source

SourceDemoDocs

Contributors

Anthony Fu
Scott Bedard
Shinigami
wheat
Alex Kozack
Antério Vieira

Changelog

v4.11.2 on 5/30/2021
68c7d - feat(typedef): add return typedefs (#543) (#544)
v5.0.0-beta.2 on 5/25/2021
5bede - feat: introduce components & directives (#486)
v4.9.3 on 5/11/2021
0fff6 - feat!: introduce controls option
v4.3.2 on 3/5/2021
bc09b - feat: support interval option
useTimestamp has loaded