Created
July 16, 2015 10:27
-
-
Save maartenpaauw/65d82a8fdf81802c60fd to your computer and use it in GitHub Desktop.
Parse the IFTTT date to dd-mm-yyyy hh:mm:00
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function IFTTT_DATE(str){ | |
var time = str.split(" "), months, timestring, parsed_hour, | |
year, month, day, hour, minute, output; | |
months = { | |
"Jan": "01", "January": "01", | |
"Feb": "02", "February": "02", | |
"Mar": "03", "March": "03", | |
"Apr": "04", "April": "04", | |
"May": "05", | |
"Jun": "06", "June": "06", | |
"Jul": "07", "July": "07", | |
"Aug": "08", "August": "08", | |
"Sep": "09", "Sept": "09", "September": "09", | |
"Oct": "10", "October": "10", | |
"Nov": "11", "November": "11", | |
"Dec": "12", "December": "12" | |
}; | |
year = time[2]; | |
month = months[time[0]]; | |
day = time[1].replace(",",""); | |
timestring = time[4].split(":"); | |
parsed_hour = (+timestring[0]).toFixed(0); | |
if (time[4].indexOf("PM") > -1 && parsed_hour < 12) { | |
hour = +parsed_hour + 12; | |
} else { | |
hour = parsed_hour; | |
if(hour <= 9) { | |
hour = "0" + hour; | |
} | |
} | |
minute = timestring[1].substring(0, timestring[1].length - 2); | |
output = day + "-" + month + "-" + year + " " + hour + ":" + minute + ":00"; | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this work in Google Scripts for SpreadSheet?