JSFiddle - React, Tailwind, and code Playground
by timhuang
JavaScript
function formatDateTimeForCloudSearch(text){
var textArray = text.split("/");
if(textArray.length==3){
if(textArray[0]<1000){
return textArray[2] + "-" + strRight("00"+textArray[0],2) + "-" + strRight("00" + textArray[1],2) + "T00:00:00Z";
}else{
return textArray[0] + "-" + strRight("00"+textArray[1],2) + "-" + strRight("00"+textArray[2],2) + "T00:00:00Z";
}
}else{
// something wrong
}
}
function strRight(text, nums){
return text.substr(text.length - nums);
}
alert(formatDateTimeForCloudSearch("2012/1/1"));