Whenever I get a timestamp value like "yyyymmddhhMMss", if necessary, I convert it to "unixtime" with a JavaScript preprocessing step.
This script is usually sufficient:
I was wondering if anyone has a better way to do this kind of conversion?.
This script is usually sufficient:
Code:
// checks if the input value is null
if (isNaN(Date.parse(value))) { return 0; }
// break the timestamp string into date and time values
var year = parseInt(value.substring(0, 4), 10);
var month = parseInt(value.substring(4, 6), 10) - 1;
var day = parseInt(value.substring(6, 8), 10);
var hour = parseInt(value.substring(8, 10), 10);
var minute = parseInt(value.substring(10, 12), 10);
var second = parseInt(value.substring(12, 14), 10);
// creates a new date and time object and converts it to unixtime
var dateTime = new Date(year, month, day, hour, minute, second);
var unixtime = dateTime.getTime() / 1000;
return unixtime;
Comment