diff options
Diffstat (limited to 'files/pt-br/web/javascript/reference/global_objects/date/gettime/index.html')
| -rw-r--r-- | files/pt-br/web/javascript/reference/global_objects/date/gettime/index.html | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/files/pt-br/web/javascript/reference/global_objects/date/gettime/index.html b/files/pt-br/web/javascript/reference/global_objects/date/gettime/index.html new file mode 100644 index 0000000000..15bf8855fb --- /dev/null +++ b/files/pt-br/web/javascript/reference/global_objects/date/gettime/index.html @@ -0,0 +1,137 @@ +--- +title: Date.prototype.getTime() +slug: Web/JavaScript/Reference/Global_Objects/Date/getTime +translation_of: Web/JavaScript/Reference/Global_Objects/Date/getTime +--- +<div>{{JSRef}}</div> + +<p>O método <strong><code>getTime()</code></strong> retorna o valor numérico correspondente ao horário da data especificada de acordo com o horário universal.</p> + +<p>Você pode usar este método para atribuir uma data e horário a outro objeto {{jsxref("Date")}}. Este método é funcionalmente equivalente ao método {{jsxref("Date.valueof", "valueOf()")}}.</p> + +<h2 id="Sintaxe">Sintaxe</h2> + +<pre class="syntaxbox"><code><var>dateObj</var>.getTime()</code></pre> + +<h3 id="Retorna">Retorna</h3> + +<p>Um número representando os milissegundos passados entre 1 de Janeiro de 1970 00:00:00 UTC e a data atual.</p> + +<h2 id="Exemplos">Exemplos</h2> + +<h3 id="Usando_getTime()_para_duplicar_datas">Usando <code>getTime()</code> para duplicar datas</h3> + +<p>Construindo um objeto de data com um horário idêntico.</p> + +<pre class="brush: js">// Sendo o mês iniciado em zero, birthday será 10 de Janeiro de 1995 +var birthday = new Date(1994, 12, 10); +var copy = new Date(); +copy.setTime(birthday.getTime()); +</pre> + +<h3 id="Medindo_tempo_de_execução">Medindo tempo de execução</h3> + +<p>Subtrair duas chamadas subsequentes a <code>getTime()</code> em objetos {{jsxref("Date")}} recém criados resultará no intervalo de tempo entre essas duas chamadas. Isso pode ser usado para calcular o tempo de execução de algumas operações. Veja também {{jsxref("Date.now()")}} para evitar instanciar objetos {{jsxref("Date")}} desnecessariamente.</p> + +<pre class="brush: js">var end, start; + +start = new Date(); +for (var i = 0; i < 1000; i++) { + Math.sqrt(i); +} +end = new Date(); + +console.log('Operation took ' + (end.getTime() - start.getTime()) + ' msec'); +</pre> + +<h2 id="Especificações">Especificações</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES1')}}</td> + <td>{{Spec2('ES1')}}</td> + <td>Definição inicial. Implementado em 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> + <tr> + <td>{{SpecName('ESDraft', '#sec-date.prototype.gettime', 'Date.prototype.getTime')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilidade_de_browsers">Compatibilidade de browsers</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Suporte básico</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>Feature</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>Suporte básico</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="See_also">See also</h2> + +<ul> + <li>{{jsxref("Date.prototype.setTime()")}}</li> + <li>{{jsxref("Date.prototype.valueOf()")}}</li> + <li>{{jsxref("Date.now()")}}</li> +</ul> |
