javascript - Node csv-stringify format timestamp column -


i'm converting list of objects csv using node csv-stringify package.

one of columns contains time-stamp , stringify method converting epoch date.

var stringify = require('csv-stringify');  ...  input = [ {'field1':'val1', 'timemodified':'2016-08-16t23:00:00.000z'}, ... ]  stringify(input, function(err, output){ console.log(output); }) 

the timemodified in output formatted as:

1471388400000 

how can maintain original time stamp formatting in output?

i tried using formatters option had no effect: http://csv.adaltas.com/stringify/examples/

 stringify(input, {formatters: {       "timemodified": function(value){         return value.format("yyyy/mm/dd hh:mm:ss");       }     }},function(err, output) {       fs.writefile('userupload.csv', output, 'utf8', function(err) {         if (err) {           console.log('error - file either not saved or corrupted file saved.');         } else {           console.log('userupload.csv file saved!');         }       });     }); 

i tried code without custom formatter , works expected. 'val1,2016-08-16t23:00:00.000z' output.

but timestamp if have date object in input like:

input = [ {'field1':'val1', 'timemodified': new date('2016-08-16t23:00:00.000z')}, ... ] 

please check if there date objects in input.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -