SVGSVGElement: getCurrentTime() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

The getCurrentTime() method of the SVGSVGElement interface returns the current time in seconds relative to the start time for the current SVG document fragment.

If getCurrentTime() is called before the document timeline has begun (for example, by script running in a <script> element before the document's SVGLoad event is dispatched), then 0 is returned.

Syntax

js
getCurrentTime()

Parameters

None.

Return value

A float.

Examples

Getting the Current Time

html
<svg
  id="exampleSVG"
  width="200"
  height="200"
  xmlns="http://www.w3.org/2000/svg">
  <circle id="circle1" cx="100" cy="100" r="50" fill="blue" />
</svg>
<button id="getTimeButton">Get Current Time</button>
<p id="currentTimeDisplay"></p>
js
const svgElement = document.getElementById("exampleSVG");
const getTimeButton = document.getElementById("getTimeButton");
const currentTimeDisplay = document.getElementById("currentTimeDisplay");

getTimeButton.addEventListener("click", () => {
  const currentTime = svgElement.getCurrentTime();
  currentTimeDisplay.textContent = `Current time in the SVG: ${currentTime} seconds`;
});

Specifications

Specification
SVG Animations Level 2
# __svg__SVGSVGElement__getCurrentTime

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
getCurrentTime

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support