JavaScriptのsplitメソッドで要素を分割し配列に格納します。
以下のhtmlの構造でテストします。
<ul>
<li>2020-10-18T05:28:03</li>
<li>2020-10-05T23:46:12</li>
<li>2020-09-30T18:50:33</li>
<li>2020-09-09T19:03:48</li>
</ul>
splitメソッドは指定した文字列で要素を分割します。タイムスタンプの「'T'」を区切りの文字列にして日付と時刻を分割し、配列に格納します。日付は配列created_date01の0番目のデータ、時刻はcreated_date01の1番目のデータとしてconsole.logで出力します。
$(function() {
var created_date01 = [];
$('ul li').each(function() {
created_date01 = $(this).text().split('T');
console.log(created_date01[0]);
});
$('ul li').each(function() {
created_date01 = $(this).text().split('T');
console.log(created_date01[1]);
});
});
2020-10-18
2020-10-05
2020-09-30
2020-09-09
05:28:03
23:46:12
18:50:33
19:03:48
次に、日付をハイフンではなくスラッシュ区切りで出力します。日付のデータをsplitメソッドで区切り文字にハイフンを指定して分割し配列にします。その配列の要素をjoinメソッドで区切り文字にスラッシュを指定して連結し、生成した文字列を変数created_date02に格納します。
$(function() {
var created_date01 = [];
var created_date02;
$('ul li').each(function() {
created_date01 = $(this).text().split('T');
created_date02 = created_date01[0].split('-').join('/');
console.log(created_date02);
});
});
2020/10/18
2020/10/05
2020/09/30
2020/09/09





