diff options
Diffstat (limited to 'files/ca/web/javascript/reference/global_objects/date/gettime/index.html')
-rw-r--r-- | files/ca/web/javascript/reference/global_objects/date/gettime/index.html | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/files/ca/web/javascript/reference/global_objects/date/gettime/index.html b/files/ca/web/javascript/reference/global_objects/date/gettime/index.html new file mode 100644 index 0000000000..20c45f31c5 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/date/gettime/index.html @@ -0,0 +1,135 @@ +--- +title: Date.prototype.getTime() +slug: Web/JavaScript/Referencia/Objectes_globals/Date/getTime +translation_of: Web/JavaScript/Reference/Global_Objects/Date/getTime +--- +<div>{{JSRef}}</div> + +<p>El mètode <strong><code>getTime()</code></strong> retorna el valor numèric corresponent a l'hora per a la data especificada, d'acord al temps universal.</p> + +<p>Es pot emprar aquest mètode com a ajuda per a proporcionar una data i hora per a un altre objecte de tipus {{jsxref("Global_Objects/Date", "Date")}}. Aquest mètode és funcionalment equivalnet al mètode {{jsxref("Date.valueof", "valueOf()")}}.</p> + +<h2 id="Sintaxi">Sintaxi</h2> + +<pre class="syntaxbox"><code><var>dateObj</var>.getTime()</code></pre> + +<h3 id="Paràmetres">Paràmetres</h3> + +<p>Cap.</p> + +<h3 id="Retorn">Retorn</h3> + +<p>El valor retornat pel mètode <code>getTime()</code> és el nombre de milisegons que han passat des de l'1 de gener de 1970 00:00:00 UTC.</p> + +<h2 id="Exemples">Exemples</h2> + +<h3 id="Utilitzar_getTime()_per_a_obtindre_dates">Utilitzar <code>getTime()</code> per a obtindre dates</h3> + +<p>Construïr un objecte date que representi el mateix moment.</p> + +<pre class="brush: js">var aniversari = new Date(1994, 12, 10); +var copia= new Date(); +copia.setTime(aniversari.getTime()); +</pre> + +<h3 id="Mesurar_el_temps_d'execució">Mesurar el temps d'execució</h3> + +<p>Restar dos crides seguides de <code>getTime()</code> en objectes {{jsxref("Date")}} acabats de generar dóne el temps transcorregut entre les dues crides. Això pot ser emprat per a calcular el temps d'execució d'algunes operacions. Vegeu també {{jsxref("Date.now()")}} per a prevenir l'instanciació d'objectes {{jsxref("Date")}} innecesaris.</p> + +<pre class="brush: js">var fi, inici; + +inici= new Date(); +for (var i = 0; i < 1000; i++) { + Math.sqrt(i); +} +fi = new Date(); + +console.log("L'operació ha trigat " + (fi.getTime() - inici.getTime()) + ' ms'); +</pre> + +<h2 id="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>ECMAScript 1a Edició.</td> + <td>Standard</td> + <td>Definició inicial. Implementat a JavaScript 1.0.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.9.5.9', 'Date.prototype.getTime')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-date.prototype.gettime', 'Date.prototype.getTime')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Característica</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Suport bàsic</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Característica</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Suport bàsic</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Vegeu_també">Vegeu també</h2> + +<ul> + <li>{{jsxref("Date.prototype.setTime()")}}</li> + <li>{{jsxref("Date.prototype.valueOf()")}}</li> + <li>{{jsxref("Date.now()")}}</li> +</ul> |