Skip to content

Instantly share code, notes, and snippets.

@mas3
Last active December 20, 2015 19:49
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 mas3/6186231 to your computer and use it in GitHub Desktop.
Save mas3/6186231 to your computer and use it in GitHub Desktop.
エポック秒→日時変換(「スクリプト実行」用スクリプト)
/*
* エポック秒→日時変換
*
* 「スクリプト実行」用スクリプト
* http://books.ivory.ne.jp/execscript/
*/
var lines = data.split("\n"),
line,
i,
datetime,
year, month, day, hour, min, sec,
outdata = new Array(),
lpad = function (val, paddedLength) {
var str = val + "",
length = str.length,
i;
if (length >= paddedLength) {
return str;
}
for (i = length; i < paddedLength; i++) {
str = '0' + str;
}
return str;
};
for (i = 0; i < lines.length; i++) {
line = lines[i];
if (line === "") {
continue;
}
if (! /^[0-9]+$/.test(line)) {
outdata.push("format error. [" + line + "]");
continue;
}
datetime = new Date(line * 1000);
year = datetime.getFullYear();
month = lpad(datetime.getMonth() + 1, 2);
day = lpad(datetime.getDate(), 2);
hour = lpad(datetime.getHours(), 2);
min = lpad(datetime.getMinutes(), 2);
sec = lpad(datetime.getSeconds(), 2);
outdata.push(
year + "-" + month + "-" + day + " "
+ hour + ":" + min + ':' + sec
);
}
return outdata.join("\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment