在js里面怎么把时间类型转换成字符串

2024-12-20 02:49:35
推荐回答(1个)
回答1:

在js里面怎么把时间类型转换成字符串
方法一:
var temper="2009-6-28 15:23"
var dt = new Date(temper.replace(/-/,"/"))
alert(dt)

方法二:
function ConvertDateFromString(dateString) {
if (dateString) {
var arr1 = dateString.split(" ");
var sdate = arr1[0].split('-');
var date = new Date(sdate[0], sdate[1], sdate[2]);
return date;
}
}
获得一个月中的总天数:
function GetDayInMonth(day) {
var today = day;
var year = today.getFullYear();
if (year < 2000) year += 1900; // Y2K fix
var month = today.getMonth();
var monarr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
monarr[1] = 29;
return monarr[month];
}