Estoy tratando de comparar algunas fechas en javascript.javascript Fecha(). GetTime() no es una función
Por alguna razón, me estoy poniendo "Tue May 01 2012 16:43:03 GMT + 0900 (JST) no tiene un método 'getTime'"
Por supuesto, strings don't have methods
que comenzó con este código dentro de una devolución de llamada, pero estaba fallando en getTime()
en la línea que crea var age
:
for (var i = 0; i < array_of_usage_indices.length; i++) {
store.get(array_of_usage_indices[i]['key'],function(may_need_gc) {
if(may_need_gc) {
var now = Date();
var created = Date(may_need_gc['value']);
var age = now.getTime()-created.getTime();
}
})
}
he Pared hacia abajo por lo que mi página de ejemplo es, literalmente, sólo esto:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>date test</title>
</head>
<body>
<script type="text/javascript" charset="utf-8">
var now = Date();
alert(now.getTime());
var t = Date().getTime();
</script>
</body>
</html>
Esto falla en Chrome 18.0.1025.168 y Firefox 13.0.
Imágenes de lo que he intentado:
Así que mi pregunta:
wth?
¿Debo usar ParseDate()? ¿Por qué no está funcionando?
¿por qué does .now() no funciona pero .getTime() hace? – clocksmith
@clocksmith 'Date.now()' (note: no parens) funciona, '.getTime()' necesita un objeto Date. Consulte también http://stackoverflow.com/questions/12517359/performance-date-now-vs-date-gettime Docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Fecha/ahora y https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime – handle