Javascript获取日期的函数(很老很土,省的每次查了)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>MyHtml.html</title><script type="text/javascript"><!--/** * 获取年、月、日、时、分、秒、毫秒 */var nowDate = new Date();var nowYear = nowDate.getFullYear();// 从 Date 对象以四位数字返回年份。请注意“getYear() + 1900”那种方式已经不推荐使用var nowMonth = nowDate.getMonth() + 1;// 从 Date 对象返回月份 (0 ~ 11)。所以加1var nowDay = nowDate.getDate();// 从 Date 对象返回一个月中的某一天 (1 ~ 31)。var nowWeek = nowDate.getDay();// 从 Date 对象返回一周中的某一天 (0 ~ 6)。var nowHour = nowDate.getHours();// 返回 Date 对象的小时 (0 ~ 23)。var nowMinute = nowDate.getMinutes();// 返回 Date 对象的分钟 (0 ~ 59)。var nowSec = nowDate.getSeconds();// 返回 Date 对象的秒数 (0 ~ 59)。var nowMilliSec = nowDate.getMilliseconds();// 返回 Date 对象的毫秒(0 ~ 999)。document.write(nowYear + "年"); document.write(nowMonth + "月");document.write(nowDay + "日");document.write(nowHour + "时");document.write(nowMinute + "分");document.write(nowSec < 10 ? ("0" + nowSec) : nowSec + "秒");document.write(nowMilliSec + "毫秒");/** * 其他常用的 */ document.write('<br />' + nowDate.toLocaleString());// 根据本地时间格式,把 Date 对象转换为字符串。document.write('<br />' + nowDate.toLocaleDateString());// 根据本地时间格式,把 Date 对象的日期部分转换为字符串。document.write('<br />' + nowDate.toLocaleTimeString());// 根据本地时间格式,把 Date 对象的时间部分转换为字符串。document.write('<br />' + nowDate.getTime());// 返回 1970 年 1 月 1 日至今的毫秒数。 //--></script></head> <body></body></html>2010年4月16日9时56分45秒190毫秒Fri Apr 16 2010 09:56:45 GMT+0800 (China Standard Time)Friday, April 16, 201009:56:451271383005190