Skip to content

Instantly share code, notes, and snippets.

@raineorshine
Created March 18, 2014 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raineorshine/9632311 to your computer and use it in GitHub Desktop.
Save raineorshine/9632311 to your computer and use it in GitHub Desktop.
A simple node script to convert a file of date strings to milliseconds.
./dateparse.js dates.txt out.txt
#!/usr/bin/env node
var fs = require('fs');
// load file
var datesText = fs.readFileSync(process.argv[2]).toString();
// convert date strings to milliseconds
var times = datesText
.split('\n')
.map(function(dateString) {
return new Date(dateString).getTime();
})
.join('\n');
// write times to output file
fs.writeFile(process.argv[3], times);
2014-03-10 00:00
2014-03-18 00:00
2014-04-01 00:00
1394431200000
1395122400000
1396332000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment