我正在开发一个flash项目,它通过php使用数据库中的xml数据来生成图形。要在正确的位置绘制所有内容,我想将日期转换为数字,我认为Date.UTC(YYYY,MM,DD)就是答案。但由于某种原因,它不会线性转换。 as3-code:
private function valuedispatcher(e:Event):void {
debugfield.appendText("succes= "+e.target.data.succes);
if (e.target.data.succes) {
var myxml:XML = new XML(e.target.data.xml);
var mylist:XMLList = new XMLList(myxml.children());
debugfield.appendText("\nxml[0]= " + mylist[0]);
debugfield.appendText("\nxml[0].time= "+mylist[0].time);
for (var i:int = 0; i < mylist.length(); i++) {
var splitter:Array = String(mylist[i].time).split("-");
var seconds:Number = Date.UTC(int(splitter[0]),int(splitter[1]),int(splitter[2]),1,0,0,0);
var ar:Array = [mylist[i].time, seconds, mylist[i].verbruik, mylist[i].corr];
debugfield.appendText("\nar= "+ar);
maxtot = Math.max(maxtot,mylist[i].verbruik,mylist[i].corr);
values.push(ar);
if(mylist[i].corr!=null){
compareNr++;
cumul1 += mylist[i + 365].verbruik;
cumul2 += mylist[i].corr;
}
}
}
else { fakedata();
debugfield.appendText("\n values= "+values);
}
}
private function fakedata():void {
var date: Date = new Date(2012, 01, 28);
var first:Boolean = true;
var corr;
for (var i:int = 0; i <= 500; i++) {
var dateString:String = "" + date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate();
var UTCseconds:Number = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate());
var gebr:Number;
if (first) {
gebr = Math.round((2.3 + Math.random() * 40) * 1000) / 1000;
first = false;
}
else {
gebr = Math.round((Math.max(4, Math.min(47, values[i - 1][2] - 5 + Math.random() * 10)))*1000)/1000;
}
corr = 10;
if (i > 134) corr = -1;
var ar:Array = [dateString, UTCseconds, gebr, corr];
values.push(ar);
maxtot = Math.max(maxtot, gebr, corr);
if(corr!=-1){
compareNr++;
}
date.date++;
}
for (var j:int = 0; j < compareNr; j++)
{
corr = values[j][2] * 0.6 + values[j + 365][2] * 0.4;
values[j][3] = corr;
cumul1 += values[j + 365][2];
cumul2 += values[j][3];
}
}
因此当我离线操作时会调用函数 fakedata(),否则它应该使用xml数据。
我现在似乎遇到的问题是'web-mode': Date.UTC(2012,1,31)= 1330646400000&gt; Date.UTC(2012,2,1)= 1330560000000 而它等于Date.UTC(2012,2,2)= 1330646400000
在离线模式下,行date.date ++似乎直接从2012 | 1 | 29到2012 | 2 | 2
这里发生了什么???
在线调试域输出:
succes= true
xml[0]= <tag>
<time>2012-01-31</time>
<verbruik>51.413</verbruik>
<corr>41.239</corr>
</tag>
xml[0].time= 2012-01-31
ar= 2012-01-31,1330650000000,51.413,41.239
ar= 2012-02-01,1330563600000,44.178,43.196
ar= 2012-02-02,1330650000000,24.790,42.459
ar= 2012-02-03,1330736400000,51.494,57.789
ar= 2012-02-04,1330822800000,36.498,43.010
ar= 2012-02-05,1330909200000,32.483,40.951
ar= 2012-02-06,1330995600000,32.347,31.762
ar= 2012-02-07,1331082000000,47.655,45.023
ar= 2012-02-08,1331168400000,44.164,39.372
ar= 2012-02-09,1331254800000,44.016,52.159
ar= 2012-02-10,1331341200000,48.150,50.561
ar= 2012-02-11,1331427600000,59.129,59.882
ar= 2012-02-12,1331514000000,52.112,43.381
ar= 2012-02-13,1331600400000,44.064,41.240
ar= 2012-02-14,1331686800000,47.609,55.833
ar= 2012-02-15,1331773200000,40.153,55.569
ar= 2012-02-16,1331859600000,51.860,43.342
ar= 2012-02-17,1331946000000,40.252,30.049
ar= 2012-02-18,1332032400000,32.464,26.127
脱机调试域输出
succes= undefined
values= 2012-1-28,1330387200000,36.374,27.516000000000002,2012-1-29,1330473600000,33.566,24.077600000000004,2012-2-1,1330560000000,30.34,23.54,2012-2-2,1330646400000,29.529,21.6454,2012-2-3,1330732800000,29.413,22.931,2012-2-4,1330819200000,30.146,22.745199999999997,2012-2-5,1330905600000,27.961,20.565399999999997,2012-2-6,1330992000000,25.279,20.3054,2012-2-7,1331078400000,25.454,22.2524,2012-2-8,1331164800000,23.905,22.4102,2012-2-9,1331251200000,19.356,20.044400000000003,2012-2-10,1331337600000,18.32,17.900399999999998,2012-2-11,1331424000000,15.984,16.8312,2012-2-12,1331510400000,11.598,14.224400000000001,2012-2-13,1331596800000,13.081,16.643,2012-2-14,1331683200000,13.842,18.5728,2012-2-15,1331769600000,13.669,17.867,2012-2-16,1331856000000,17.472,20.4096,2012-2-17,1331942400000,17.512,18.714,2012-2-18,1332028800000,18.39,18.971200000000003,2012-2-19,1332115200000,21.985,19.235799999999998,2012-2-20,1332201600000,18.049,18.2298,2012-2-21,1332288000000,20.269,18.0362,2012-2-22,1332374400000,19.88,15.9452,2012-2-23,1332460800000,17.259,16.1194,2012-2-24,1332547200000,13.054,14.1248,2012-2-25,1332633600000,8.401,10.4042,2012-2-26,1332720000000,7.112,11.0588,2012-2-27,1332806400000,5.487,9.2158,2012-2-