winston:how to change timestamp format

The timestamp option can be a function that returns what you wish it to be saved as...

Line 4:

winston.add(winston.transports.Console, {'timestamp':function() {return '111111111'; },'colorize':true});

Source here: https://github.com/flatiron/winston/pull/120


winston@3 version

winston.createLogger({
  format: winston.format.combine(
    winston.format.timestamp({format: 'YYYY-MM-DD HH:mm:ss'}),
    winston.format.prettyPrint()
  ),
  transports: [
    new winston.transports.Console()
  ]
})

To support timezone, you need to change format to a function which winston will call.

const timezoned = () => {
  return new Date().toLocaleString('en-US', {
    timeZone: 'Asia/Shanghai'
  });
};

const logger = createLogger({
  format: combine(
    timestamp({
      format: timezonedTime
    })
  ),
  transport: [
    new transports.Console(),
  ]
});

For a good result, you may use momentjs:

const moment = require('moment');
...
...
timestamp: () => moment().format('YYYY-MM-DD hh:mm:ss')