i'm trying to get a local timestamp in a controller that won't be used in a view (ie filter not an option)
(for info it's to be written into an SQLite db as a local 'date created' field)
the following gets me the date - but is in the wrong format:
var current_time = new Date();
console.log('current_time:', current_time);
which gives me date in the format current_time: Thu Dec 18 2014 23:16:27 GMT-0800 (PST)
the following also works (which partially solves my problem - since i think i can use UTC):
var current_time = new Date().getTime();
console.log('current_time:', current_time);
which gives current_time: 1418973515745
however it's UTC according to the docs
however this (which i thought was the solution) does not work:
var current_time = new Date.now();
console.log('current_time:', current_time);
gives me the following error:
TypeError: function now() { [native code] } is not a constructor
according to the javascript docs I've got the right formats etc...
the Angular docs don't mention anything specific (mostly seems to be how to get from timestamp to human readable, not the other way around)
so for curiosity:
- is there any reason
Date.now()
shouldn't work in Angular? ..am I writing something wrong ? - why would
Date().getTime()
work butDate.now()
not ? - how do i get local js timestamp variable in Angular without using a filter ? ...and without using a separate longwinded directive as suggested in AngularJs get Timestamp from a human readable date