我使用了一个日期选择器,它有日,月和年。但它没有时间(秒,分钟和小时)。我已经在谷歌电子表格中插入了记录。但是当我在日期记录中专门搜索和检索记录时,我遇到了问题。
例如,如果谷歌电子表格中的日期是3/25/2017。当我搜索记录时,日期值返回2017-03-24T15:00:00.000Z,其中日期减少一天。
如何解决此问题?
请帮忙。
代码
Html
<div id="Searchrecord">
<h2>Search </h2>
<form id="fsrecord">
<input type="text" name="sinvoice" id="sinvoice" placeholder="by invoice number"/> <br/>
<input type="text" name="surname" id="surname" placeholder="by your name"/> <br/>
<input type="text" name="scustomername" id="scustomername" placeholder="by customer name"/> <br/>
<input type="text" name="spayementdate" id="spayementdate" placeholder="by payment date"> <br>
<input type="submit" value="search" />
</form>
</div>
<div id="searchresult">
</div>
<script>
$( document ).ready(function() {
$("#spayementdate").datepicker();
$("#fsrecord").submit(function() {
google.script.run.withSuccessHandler(function(retsearch){
var response = JSON.parse(retsearch);
var newHTML=[];
newHTML.push('<table>' + '<tr>' +'<td>'+"Invoice"+'</td>'+
'<td>'+"Your Name"+'</td>'+
'<td>'+"Customer Name" +'</td>'+
'<td>'+"Email" + '</td>'+
'<td>'+"Project Name" + '</td>'+
'<td>'+"Amount of Money" + '</td>'+
'<td>'+"Payment Date" +'</td>'+
'<td>'+"Date Create" +'</td>'+
'<td>'+"Branch" +'</td>'+
'<td>'+ "File url" +'</td>'
+ '<tr>');
for(var i =0 ; i< response.length ; i++){
newHTML.push('<tr>' + '<td>'+ response[i].invoice + '</td>'
+ '<td>'+ response[i].yourname + '</td>'
+ '<td>'+ response[i].customername + '</td>'
+ '<td>'+ response[i].email + '</td>'
+ '<td>'+ response[i].projectname + '</td>'
+ '<td>'+ response[i].amountofmoney + '</td>'
+ '<td>'+ response[i].paymentday + '</td>'
+ '<td>'+ response[i].datecreate + '</td>'
+ '<td>'+ response[i].branch + '</td>'
+ '<td>'+ '<a href="' + response[i].file + '" target="_blank" >file!</a>' + '</td>'
+'</tr>');
}
newHTML.push('</table>');
$("#results").hide();
$("#searchresult").html(newHTML.join(""));
}).processSearch(this);
});
});
</script>
Code.cs
function getData() {
var ss=SpreadsheetApp.openById('1PWJyASHmjJ_W8-72u8bbrGbN-Nv6kdkCvjdmYuNNlEY');
var sheet=ss.getSheetByName('invoice1');
return sheet;
}
function processSearch(searchform){
var sheet = getData();
var data = ObjApp.rangeToObjects(sheet.getDataRange().getValues());
var searchinvoice=searchform.sinvoice;
var searchfname=searchform.surname;
var searchcname=searchform.scustomername;
var searchpayementdate=searchform.spayementdate;
var results = [];
var events;
for(var i=0 ; i < data.length ; i++) {
if(searchinvoice == data[i].invoice) {
events ={invoice:data[i].invoice,yourname:data[i].yourname, customername:data[i].customername,email:data[i].email,projectname:data[i].projectname,amountofmoney:data[i].amountofmoney,paymentday:data[i].paymentday,datecreate:data[i].datecreate,branch:data[i].branch,file:data[i].file };
results.push(events);
return JSON.stringify(results);
}
}
//Logger.log(results);
return JSON.stringify(results);
}
答案 0 :(得分:0)
我认为你可能有两个问题并不依赖于代码本身。
当您仅保存日期或仅保存时间时,将假定缺少部分的某些默认值。因此,如果您只保存日期,则时间部分将具有假定值,并且您只保存时间,然后日期部分将具有假设值。这些假设值在很大程度上取决于区域设置和时区设置。
请检查这些是否会影响您所看到的内容。