Fix bugs in javascript date to timestamp string method.

Fixes #2332.