I have different types of dates formatting like:
Note they are all different formats, different order, some have 2 months, some only one, I tried to use moment js with no results, I also tried to use date js yet, no luck.
I tried to do some splitting:
dates.push({
Time : []
});
function doSelect(text) {
return $wikiDOM.find(".infobox th").filter(function() {
return $(this).text() === text;
});
}
dateText = doSelect("Date").siblings('td').text().split(/s+/g);
for(var i = 0; i < dateText.length; i++) {
d += dateText[i] + ' ';
}
dates[0].Time.push(d);
But the result is:
"Time": [
"27 - 28 August 663 CE ",
Eventually what I need to auto generate is:
<ul class="Days">
<li>27</li>
<li>28</li>
</ul>
<ul class="Months">
<li>August</li>
</ul>
<ul class="Year">
<li>663</li>
</ul>
And also think of a way to handle CE
or AD
or BC
To achieve that an ideal way I'd like to use is a multidimensional array:
time.push({
Day : [],
Month : [],
Year : [],
Prefix : []
});
Probably to check max 2 numbers for days
, check months against a list of strings like January, February, March..
and then the year min 3 numbers to max 4 numbers
and then handle the prefix with some conditionals
. But yet, how about year 2 or 1
? or how about if the date is 02/9/1975
? Or with separating dash
, they'd be a new format. I think the logic is kinda there but how would you split those dates into a multidimensional array as per above given the fact that they are all different formats?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…