0

これにより、JavaScript 形式が生成されます: 2012 年 8 月 9 日

var month = [1,2,3,4,5,6,7,8,9,10,11,12];
var month2 = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var day = postdate.split(-)[2].substring(0,2);
var m = postdate.split(-)[1];
var y = postdate.split(-)[0];
for(var u2=0;u2<month.length;u2++){
if(parseInt(m)==month[u2]) {
m = month2[u2] ; break;
}
}
var daystr = day+ ' ' + m + ', ' + y ;

上記のJavaScriptで曜日名と時刻を追加するにはどうすればよいですか?
例: 2012 年 8 月 9 日木曜日の午後 5 時 28 分

4

2 に答える 2

0

getDay();dayname
getTime()は、1970 年からのミリ秒単位の時間を返します。

于 2012-08-09T10:56:10.110 に答える
0

を使用して曜日名を取得できますgatDay();

ここに時間を表示する関数があります。

function displayTime() {
            var currentTime = new Date();
            var currentHours = currentTime.getHours();
            var currentMinutes = currentTime.getMinutes();
            var currentSeconds = currentTime.getSeconds();

            // Pad the minutes and seconds with leading zeros, if required
            currentMinutes = (currentMinutes < 10 ? "0" : "" ) + currentMinutes;
            currentSeconds = (currentSeconds < 10 ? "0" : "" ) + currentSeconds;

            // Choose either "AM" or "PM" as appropriate
            var timeOfDay = (currentHours < 12 ) ? "AM" : "PM";

            // Convert the hours component to 12-hour format if needed
            currentHours = (currentHours > 12 ) ? currentHours - 12 : currentHours;

            // Convert an hours component of "0" to "12"
            currentHours = (currentHours == 0 ) ? 12 : currentHours;

            // Compose the string for display
            var currentTimeString = currentHours + ":" + currentMinutes + " " +currentSeconds+" "+ timeOfDay;

            $("#clock").html(currentTimeString);

        }
于 2012-08-09T11:14:20.913 に答える