Javscript - 具有一定周期长度的日期计算 [英] Javscript -Date calculation with a certain period length
问题描述
function checkLimit()
{
db=openDatabase(masterDbName,version,displayName,maxSize);
db.transaction(function(transaction)
{
var active=localStorage.getItem("ActiveProject");
var query='Select projdb_id from projecttable where proj_name="'+active+'"';
transaction.executeSql(query, [] , function(transaction, result)
{
if(result != null && result.rows != null)
{
if (result.rows.length != 0)
{
for (var i = 0; i < result.rows.length; i++)
{
var row = result.rows.item(i);
id=row.projdb_id;
}
}
}
db1=openDatabase(id,version,displayName,maxSize);
db1.transaction(function (t)
{
var query='Select * from customer where cust_name="'+document.getElementById('name').value+'"';
t.executeSql(query, [] , function(t, result)
{
if(result != null && result.rows != null)
{
if (result.rows.length != 0)
{
for (var i = 0; i < result.rows.length; i++)
{
var row = result.rows.item(i);
var period=row.credit_period; //period value from customer table
}
var myDate=new Date(document.getElementById('date').value),
curr_month=("0"+(myDate.getMonth()+1)).slice(-2),
day=("0"+myDate.getDate()).slice(-2);
}
}
var queryIn = 'SELECT date_format FROM params ';
var listArry =[];
db.transaction(function (tx)
{
tx.executeSql(queryIn, [], function (tx, results)
{
var len = results.rows.length, i;
if(results != null && results.rows != null)
{
if (results.rows.length != 0)
{
for (var i = 0; i < results.rows.length; i++)
{
var row = results.rows.item(i);
var dateformat=row.date_format;
}
var formDate;
if(dateformat=="dd/mm/yyy")
{
formDate= day+"/"+curr_month + "/" +myDate.getFullYear();
}
else
{
formDate= curr_month+"/"+myDate + "/" +myDate.getFullYear();
}
}
}
var dated=formDate.getDate()+period;
expDate = dated;
document.getElementById('due_date').value=expDate;
});
});
});
});
});
});
}
这是我的代码,用于获取日期格式并计算信用期并根据日期显示日期在文本框中。我有一个日期字段,用户将在该日期字段中输入日期,根据输入的日期,due_date字段应通过添加信用期值来更改..
$ b例如,如果日期是2014年6月3日且信用额度是10天......那么$ b,那么13/06/2014应该是截止日期值..
我该怎么做....上面的代码var日期= formDate.getDate()+ period;显示错误未定义的函数..
Plz help !!!
This is my code to get the format of the date and calculate the credit period and display the date according to that in textbox.I have a date field from where the user will enter the date and according to the date entered the due_date field should change by addding the credit period value..
for example if the date is 03/06/2014 and the credit limit is 10 days...then 13/06/2014 should be the due date value..
How can I do this....The above code var dated=formDate.getDate()+period; shows the error undefined function..
Plz help!!!
推荐答案
formDate = myDate.add (句号).days();
使用date.js文件中定义的add()方法。在我们的html文件中包含这个date.js。
formDate=myDate.add(period).days();
Use add() method defined in date.js file..include this date.js in our html file.
事情是formDate
不是Date
对象,它是一个字符串。并且您正在调用getDate()
Date
对象的方法。
这就是为什么undefined
。
The thing isformDate
was not aDate
object, it was a string. And you are callinggetDate()
method ofDate
object.
That's why it wasundefined
.
这篇关于Javscript - 具有一定周期长度的日期计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!