Skip to content

Instantly share code, notes, and snippets.

@YasuakiHirano
Last active July 4, 2016 01:46
Show Gist options
  • Save YasuakiHirano/cacf8defe8f6a5b440a8717f06c230f1 to your computer and use it in GitHub Desktop.
Save YasuakiHirano/cacf8defe8f6a5b440a8717f06c230f1 to your computer and use it in GitHub Desktop.
Array.prototype.indexOf = function(target){
for(var i = 0; i < this.length; i++){
if(this[i] === target){
return i;
}
}
return -1;
}
function timeChangeAmPm(data){
var amArr = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '24'];
var timeArr = {
'00':'12',
'01':'01',
'02':'02',
'03':'03',
'04':'04',
'05':'05',
'06':'06',
'07':'07',
'08':'08',
'09':'09',
'10':'10',
'11':'11',
'12':'12',
'13':'01',
'14':'02',
'15':'03',
'16':'04',
'17':'05',
'18':'06',
'19':'07',
'20':'08',
'21':'09',
'22':'10',
'23':'11',
'24':'00'
};
var dataSp = data.split(" ");
var date = dataSp[0];
var time = dataSp[1];
var timeSp = time.split(":");
var hour = timeSp[0];
var min = timeSp[1];
// am/pm判定
var apStr = "";
if(amArr.indexOf(hour) >= 0){
apStr = "AM";
} else {
apStr = "PM";
}
return date + " " + apStr + timeArr[hour] + ":" + min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment