selenium.prototype.dostoredatebyformat = function(format,args){
// format of args: month,day,year
if(args.trim().length < 3)
throw new seleniumerror("arguments must contain ""month"",""date"",""year"" variables!");
var formats = format.split(",");
var days = parseint(formats[3]);
var sysdate = getsysdate(); //get the sysdate
var specdate = dateafterdays(sysdate,parsefloat(days),1); //get specified date
var arrargs = args.split(",");
var month = specdate.getmonth()+1;
var date = specdate.getdate();
var year = specdate.getfullyear();
// get month string
switch(formats[0].touppercase()){
case "mm": // return 2 digits of month number, such as: 01
month = (month+"").length==1?"0"+month:month;
break;
case "mmm": //return the first 3 chars of the month word, such as: jan
month = this.getmonthshortname(month);
case "mmmm": //return the full word of the month word, such as: january
month = this.getmonthfullname(month);
case "m":
default:
// return 1 digit when month is lower than 10.
// do nothing
}
//get date string
switch(formats[1].touppercase()){
case "dd": //always return 2 digits of the month number, such as: 05
date = (date+"").length==1?"0"+date:date;
case "d":
// return 1 digit when date is lower than 10.
//get year string
switch(formats[2].touppercase()){
case "yy": // return last 2 digits of the year number, such as: 08 (2008)
year = (year+"").substr(2);
case "yyyy":
//return full year number, such: 2008.
storedvars[arrargs[0]] = month;
storedvars[arrargs[1]] = date;
storedvars[arrargs[2]] = year;
selenium.prototype.getmonthfullname = function(month){
var montharr = new array("january","february","march","april","may","june","july","august","september","october","november","december");
if(month == null){
throw new seleniumerror("you didn't specify a month");
try{
month = parseint(month);
}catch (e){
throw new seleniumerror("""month"" is not a integer!");
return montharr[month-1];
/* return the date n days(n*24 hours) before/after some day.
* args : num - positive/negative integer/float number,default is "1";
* type - 0 (second) or 1 (day), default is second.
* return : date
*/
function dateafterdays(date, num, type){
date = (date == null?new date():date);
num = (num == null?1:num);
if(typeof(num)!="number")
throw new seleniumerror("dateafterdays(date, num, type),""num"" argument must be number type.");
if(typeof(date)!="object")
throw new seleniumerror("dateafterdays(date, num, type),""date"" argument must be date type.");
var itype = (type == null?0:type);
var arr = [1000,86400000];
var dd = date.valueof();
dd += num * arr[itype];
var d=new date(dd);
return d;
function getsysdate(){
return new date();
使用方法如下,詳見以上代碼
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicGcq5iYtVHa05SckJndxUjMwQTNxkjM5AzMxAjMfJzN2IDO5QTMvwVOw8CXzEDMy8CXzRnbl1GajFGd0F2Lc12bj5yZulGdzVGdxUjL3d3dvw1LcpDc0RHaiojIsJye.jpg)
最新内容請見作者的github頁:http://qaseven.github.io/