RSS

Tag Archives: regexp

js timestamp

Sometimes while logging js I need to have a timestamp in the beggining of the row. There are libraries to manage timestamps and to print wonderful logs, but sometimes the needs are only to make some console.log while debugging.

This is my one-line way to handle it:

function timestamp() {
  return (new Date).toISOString().match(/([0-9]{2}:[0-9]{2}:[0-9]?[0-9].[0-9]{3})/g)[0];
}

or “keep only the time part of an ISO formatted timestamp”.

 
Leave a comment

Posted by on 2016/12/16 in dev

 

Tags: , ,