我正在使用Flash CS3创建一个基于XML的屏幕保护程序,一切正常。但是,在XML输出文件中,日期输出格式仍未格式化(YYYY-MM-DD T00:00:00+00:00
)。理想情况下,将输出英国日期(DD/MM/YYYY
)格式。
以下是驱动XML文件的ActionScript代码示例
// Load up variables with XML element data
var item_data:Array = new Array();
item_data[0] = xml_item.id;
item_data[1] = xml_item.Product_Name;
item_data[2] = xml_item.Product_Language;
item_data[3] = xml_item.dateCreated;
item_data[4] = xml_item.antDeadlineDate;
item_data[5] = xml_item.comments;
item_data[6] = xml_item.webPdf;
item_data[7] = xml_item.conCheck;
// Set output variable
output = "<b>Job ID</b>:" + item_data[0] + "\n";
output += "<b>Product Name</b>: " + item_data[1] + "\n";
output += "<b>Language</b>: " + item_data[2] + "\n";
output += "<b>Date Created</b>: " + item_data[3] + "\n";
output += "<b>Anticipated Deadline</b>: " + item_data[4] + "\n";
output += "<b>Comments</b>: " + item_data[5] + "\n";
output += "<b>PDFs created</b>: " + item_data[6] + "\n";
output += "<b>Controller Check</b>: " + item_data[7] + "\n\n\n\n";
答案 0 :(得分:2)
您也可以使用正则表达式
var xmlDateTime:RegExp = /([0-9]{4})-(0[0-9]|1[012])-([012][0-9]|3[01])T([01][0-9]|2[0-3])(:[0-5][0-9]){2}(.[0-9]{3}){0,1}(\+|-)([01][0-9]|2[0-3]):[0-5][0-9]/g;
var dateString = xml_item.dateCreated.toString().replace(xmlDateTime, "$3/$2/$1");
答案 1 :(得分:1)
要将日期格式为YYYY-MM-DD T00:00:00 + 00:00的日期字符串转换为此格式DD / MM / YYYY,您可以这样做:
var dateOld:String = '1999-01-05 T00:00:00+00:00';
var dateParts:Array = dateOld.substring(0, 10).split('-');
var dateNew:String = dateParts[2] + '/' + dateParts[1] + '/' + dateParts[0];