Metoda JavaScript Date getMilliseconds()

Definicja i użycie

Metoda getMilliseconds() zwraca milisekundy dla określonej daty i czasu (od 0 do 999).

Przykład

Przykład 1

Zwróć milisekundy na podstawie czasu lokalnego:

var d = new Date();
var n = d.getMilliseconds();

Spróbuj sam

Przykład 2

Przykład

Zwróć milisekundy dla określonej daty i czasu:

var d = new Date("July 21, 1983 01:15:00:526");
var n = d.getMilliseconds();

Spróbuj sam

Przykład 3

Wyświetl czas (w milisekundach) za pomocą getHours(), getMinutes(), getSeconds() i getMilliseconds():

function addZero(x, n) {
  while (x.toString().length < n) {
    x = "0" + x;
  }
  return x;
}
function myFunction() {
  var d = new Date();
  var x = document.getElementById("demo");
  var h = addZero(d.getHours(), 2);
  var m = addZero(d.getMinutes(), 2);
  var s = addZero(d.getSeconds(), 2);
  var ms = addZero(d.getMilliseconds(), 3);
  x.innerHTML = h + ":" + m + ":" + s + ":" + ms;
}

Spróbuj sam

Gramatyka

Date.getMilliseconds()

Parametry

Brak parametrów.

Szczegółowe informacje techniczne

Zwracana wartość: Wartości liczbowe, od 0 do 999, reprezentują milisekundy.
Wersja JavaScript: ECMAScript 1

Obsługa przeglądarek

Metoda Chrome IE Firefox Safari Opera
getMilliseconds() Wsparcie Wsparcie Wsparcie Wsparcie Wsparcie

Strony związane

Tutorial:Data JavaScript

Tutorial:Format daty JavaScript

Tutorial:Metody uzyskiwania daty JavaScript